#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 findThreadToStealFrom(int *, int *, int, int, float, int *, int *);
int /*<<< orphan*/ loop1chunk(int, int);
int /*<<< orphan*/ loop2chunk(int, int);
int omp_get_max_threads();
int omp_get_thread_num();
void runloop(int loopid) {
  int thread_count = omp_get_max_threads();
  int n_over_p = (int)ceil((double)729 / (double)thread_count);
  float one_over_p = 1.0 / thread_count;
  int lower_bounds[thread_count];
  int upper_bounds[thread_count];
#pragma omp parallel default(none) shared(thread_count, loopid, lower_bounds,  \
                                          upper_bounds, n_over_p, one_over_p)
  {
    int thread_id = omp_get_thread_num(), thread_low = thread_id * n_over_p,
        thread_high = ((thread_id + 1) * n_over_p) > 729
                          ? 729
                          : (thread_id + 1) * n_over_p;
    lower_bounds[thread_id] = thread_low;
    upper_bounds[thread_id] = thread_high;
    int current_low = 0, current_high = 0, stealing_from = 0;
    while (stealing_from != -1) {
      switch (loopid) {
      case 1:
        loop1chunk(current_low, current_high);
        break;
      case 2:
        loop2chunk(current_low, current_high);
        break;
      }
#pragma omp critical
      {
        stealing_from = findThreadToStealFrom(
            lower_bounds, upper_bounds, thread_count, thread_id, one_over_p,
            &current_low, &current_high);
      }
    }
  }
}


x86 assembly (clang, -O0):
<runloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
call   1080 <omp_get_max_threads@plt>
mov    %eax,-0x8(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe7e(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
mov    %eax,-0xc(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe6d(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
imul   -0xc(%rbp),%eax
cmp    $0x2d9,%eax
jle    1225 <runloop+0xc5>
mov    $0x2d9,%eax
mov    %eax,-0x54(%rbp)
jmp    1232 <runloop+0xd2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    -0x54(%rbp),%edx
mov    %edx,-0x34(%rbp)
mov    -0x30(%rbp),%esi
movslq -0x2c(%rbp),%rdx
mov    %esi,(%rcx,%rdx,4)
mov    -0x34(%rbp),%edx
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0xffffffff,-0x40(%rbp)
je     12db <runloop+0x17b>
mov    -0x4(%rbp),%eax
mov    %eax,-0x58(%rbp)
sub    $0x1,%eax
je     1298 <runloop+0x138>
jmp    1287 <runloop+0x127>
mov    -0x58(%rbp),%eax
sub    $0x2,%eax
je     12a8 <runloop+0x148>
jmp    12b3 <runloop+0x153>
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1060 <loop1chunk@plt>
jmp    12b3 <runloop+0x153>
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1050 <loop2chunk@plt>
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x2c(%rbp),%ecx
movss  -0x10(%rbp),%xmm0
lea    -0x38(%rbp),%r8
lea    -0x3c(%rbp),%r9
call   1070 <findThreadToStealFrom@plt>
mov    %eax,-0x40(%rbp)
jmp    1269 <runloop+0x109>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runloop>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r13d
xor    %eax,%eax
call   1080 <omp_get_max_threads@plt>
mov    %eax,%r14d
cvtsi2sd %eax,%xmm1
movsd  %xmm1,-0x38(%rbp)
movsd  0xe71(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <ceil@plt>
mov    %rax,-0x40(%rbp)
movsd  0xe64(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
mov    %r14d,%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
mov    -0x40(%rbp),%rdx
imul   %edx,%eax
lea    0x1(%rbx),%ecx
imul   %edx,%ecx
cmp    $0x2d9,%ecx
mov    $0x2d9,%edx
cmovl  %ecx,%edx
movslq %ebx,%rcx
mov    %eax,(%r15,%rcx,4)
mov    %edx,(%r12,%rcx,4)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    124d <runloop+0xed>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1050 <loop2chunk@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
movss  -0x38(%rbp),%xmm0
lea    -0x30(%rbp),%r8
lea    -0x2c(%rbp),%r9
call   1070 <findThreadToStealFrom@plt>
cmp    $0xffffffff,%eax
je     1266 <runloop+0x106>
cmp    $0x2,%r13d
je     1220 <runloop+0xc0>
cmp    $0x1,%r13d
jne    122b <runloop+0xcb>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1060 <loop1chunk@plt>
jmp    122b <runloop+0xcb>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @runloop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %2
%15 = call i32 (...) @omp_get_max_threads()
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = sitofp i32 %16 to double
%18 = fdiv double 7.290000e+02, %17
%19 = call i64 @ceil(double %18)
%20 = trunc i64 %19 to i32
store i32 %20, i32* %4
%21 = load i32, i32* %3
%22 = sitofp i32 %21 to double
%23 = fdiv double 1.000000e+00, %22
%24 = fptrunc double %23 to float
store float %24, float* %5
%25 = load i32, i32* %3
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %6
%28 = alloca i32, i64 %26
store i64 %26, i64* %7
%29 = load i32, i32* %3
%30 = zext i32 %29 to i64
%31 = alloca i32, i64 %30
store i64 %30, i64* %8
%32 = call i32 (...) @omp_get_thread_num()
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = load i32, i32* %4
%35 = mul nsw i32 %33, %34
store i32 %35, i32* %10
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %4
%39 = mul nsw i32 %37, %38
%40 = icmp sgt i32 %39, 729
br i1 %40, label %41, label %42
41: ; preds = %1
br label %47
42: ; preds = %1
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
%45 = load i32, i32* %4
%46 = mul nsw i32 %44, %45
br label %47
47: ; preds = %42, %41
%48 = phi i32 [ 729, %41 ], [ %46, %42 ]
store i32 %48, i32* %11
%49 = load i32, i32* %10
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %28, i64 %51
store i32 %49, i32* %52
%53 = load i32, i32* %11
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %31, i64 %55
store i32 %53, i32* %56
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
br label %57
57: ; preds = %70, %47
%58 = load i32, i32* %14
%59 = icmp ne i32 %58, -1
br i1 %59, label %60, label %75
60: ; preds = %57
%61 = load i32, i32* %2
switch i32 %61, label %70 [
i32 1, label %62
i32 2, label %66
]
62: ; preds = %60
%63 = load i32, i32* %12
%64 = load i32, i32* %13
%65 = call i32 @loop1chunk(i32 %63, i32 %64)
br label %70
66: ; preds = %60
%67 = load i32, i32* %12
%68 = load i32, i32* %13
%69 = call i32 @loop2chunk(i32 %67, i32 %68)
br label %70
70: ; preds = %60, %66, %62
%71 = load i32, i32* %3
%72 = load i32, i32* %9
%73 = load float, float* %5
%74 = call i32 @findThreadToStealFrom(i32* %28, i32* %31, i32 %71, i32 %72, float %73, i32* %12, i32* %13)
store i32 %74, i32* %14
br label %57
75: ; preds = %57
%76 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
define void @runloop(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32 (...) @omp_get_max_threads()
%5 = sitofp i32 %4 to double
%6 = fdiv double 7.290000e+02, %5
%7 = tail call i64 @ceil(double %6)
%8 = trunc i64 %7 to i32
%9 = fdiv double 1.000000e+00, %5
%10 = fptrunc double %9 to float
%11 = zext i32 %4 to i64
%12 = alloca i32, i64 %11
%13 = alloca i32, i64 %11
%14 = tail call i32 (...) @omp_get_thread_num()
%15 = mul nsw i32 %14, %8
%16 = add nsw i32 %14, 1
%17 = mul nsw i32 %16, %8
%18 = icmp slt i32 %17, 729
%19 = select i1 %18, i32 %17, i32 729
%20 = sext i32 %14 to i64
%21 = getelementptr inbounds i32, i32* %12, i64 %20
store i32 %15, i32* %21
%22 = getelementptr inbounds i32, i32* %13, i64 %20
store i32 %19, i32* %22
%23 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%24 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %25
25: ; preds = %1, %34
switch i32 %0, label %34 [
i32 1, label %26
i32 2, label %30
]
26: ; preds = %25
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 @loop1chunk(i32 %27, i32 %28)
br label %34
30: ; preds = %25
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = call i32 @loop2chunk(i32 %31, i32 %32)
br label %34
34: ; preds = %25, %30, %26
%35 = call i32 @findThreadToStealFrom(i32* %12, i32* %13, i32 %4, i32 %14, float %10, i32* %2, i32* %3)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %25
37: ; preds = %34
ret void
}