#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ ceil(double);
int /*<<< orphan*/ loop1chunk(int, int);
int /*<<< orphan*/ loop2chunk(int, int);
int omp_get_num_threads();
int omp_get_thread_num();
void runloop(int loopid) {
#pragma omp parallel default(none) shared(loopid)
  {
    int myid = omp_get_thread_num();
    int nthreads = omp_get_num_threads();
    int ipt = (int)ceil((double)729 / (double)nthreads);
    int lo = myid * ipt;
    int hi = (myid + 1) * ipt;
    if (hi > 729)
      hi = 729;
    switch (loopid) {
    case 1:
      loop1chunk(lo, hi);
      break;
    case 2:
      loop2chunk(lo, hi);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<runloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <omp_get_num_threads@plt>
mov    %eax,-0xc(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm1
movsd  0xe84(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2d9,-0x18(%rbp)
jle    11b3 <runloop+0x63>
movl   $0x2d9,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     11d8 <runloop+0x88>
jmp    11c7 <runloop+0x77>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     11e8 <runloop+0x98>
jmp    11f3 <runloop+0xa3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <loop1chunk@plt>
jmp    11f3 <runloop+0xa3>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <loop2chunk@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runloop>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <omp_get_num_threads@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe8f(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
mov    %ebp,%edi
imul   %eax,%edi
add    $0x1,%ebp
imul   %eax,%ebp
cmp    $0x2d9,%ebp
mov    $0x2d9,%esi
cmovl  %ebp,%esi
add    $0x8,%rsp
cmp    $0x2,%ebx
je     11a8 <runloop+0x58>
cmp    $0x1,%ebx
jne    11af <runloop+0x5f>
pop    %rbx
pop    %rbp
jmp    1060 <loop1chunk@plt>
pop    %rbx
pop    %rbp
jmp    1050 <loop2chunk@plt>
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @runloop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = call i32 (...) @omp_get_thread_num()
store i32 %8, i32* %3
%9 = call i32 (...) @omp_get_num_threads()
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = sitofp i32 %10 to double
%12 = fdiv double 7.290000e+02, %11
%13 = call i64 @ceil(double %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = load i32, i32* %5
%17 = mul nsw i32 %15, %16
store i32 %17, i32* %6
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = load i32, i32* %5
%21 = mul nsw i32 %19, %20
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 729
br i1 %23, label %24, label %25
24: ; preds = %1
store i32 729, i32* %7
br label %25
25: ; preds = %24, %1
%26 = load i32, i32* %2
switch i32 %26, label %35 [
i32 1, label %27
i32 2, label %31
]
27: ; preds = %25
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 @loop1chunk(i32 %28, i32 %29)
br label %35
31: ; preds = %25
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = call i32 @loop2chunk(i32 %32, i32 %33)
br label %35
35: ; preds = %25, %31, %27
ret void
}

LLVM IR (-O2):
define void @runloop(i32 %0) {
%2 = tail call i32 (...) @omp_get_thread_num()
%3 = tail call i32 (...) @omp_get_num_threads()
%4 = sitofp i32 %3 to double
%5 = fdiv double 7.290000e+02, %4
%6 = tail call i64 @ceil(double %5)
%7 = trunc i64 %6 to i32
%8 = mul nsw i32 %2, %7
%9 = add nsw i32 %2, 1
%10 = mul nsw i32 %9, %7
%11 = icmp slt i32 %10, 729
%12 = select i1 %11, i32 %10, i32 729
switch i32 %0, label %17 [
i32 1, label %13
i32 2, label %15
]
13: ; preds = %1
%14 = tail call i32 @loop1chunk(i32 %8, i32 %12)
br label %17
15: ; preds = %1
%16 = tail call i32 @loop2chunk(i32 %8, i32 %12)
br label %17
17: ; preds = %1, %15, %13
ret void
}