#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 */
int omp_get_num_threads();
int omp_get_thread_num();
int /*<<< orphan*/ printf(char *, double, ...);
double shubert(double, double);
int main() {
  const int MAX_STEPS = 8;
  const int LOWER_BOUND = -2;
  const double STEP_SIZE = 0.5;
  int threadCount = 0;
  int tid = 0;
  int i = 0;
  double x1, x2, y = 0;
  double min = 99;
#pragma omp parallel for private(tid) reduction(min : min)
  for (i = 0; i <= MAX_STEPS; i++) {
    if (tid == 0 && i == 1) {
      threadCount = omp_get_num_threads();
      printf("Number of threads = %d\n", threadCount);
    }
    tid = omp_get_thread_num();
    x1 = STEP_SIZE * i + LOWER_BOUND;
    printf("Thread #%d, i = %d\n", tid, i);
    for (x2 = -2; x2 <= 2; x2 += 0.5) {
      y = shubert(x1, x2);
      min = (y < min) ? y : min;
    }
  }
  printf("Global min = %.2f\n", min);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x8,-0x8(%rbp)
movl   $0xfffffffe,-0xc(%rbp)
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe71(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jg     12ad <main+0x16d>
cmpl   $0x0,-0x20(%rbp)
jne    11d6 <main+0x96>
cmpl   $0x1,-0x24(%rbp)
jne    11d6 <main+0x96>
mov    $0x0,%al
call   1050 <omp_get_num_threads@plt>
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
lea    0xe51(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xe1b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe17(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
mov    -0x24(%rbp),%esi
lea    0xe27(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xdf0(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xdeb(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     129a <main+0x15a>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
call   1060 <shubert@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    126f <main+0x12f>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1279 <main+0x139>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd7d(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1225 <main+0xe5>
jmp    129f <main+0x15f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119b <main+0x5b>
movsd  -0x48(%rbp),%xmm0
lea    0xd93(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0xea5(%rip),%xmm0
lea    0xee6(%rip),%r14
lea    0xef7(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    12d7 <main+0x197>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
mov    %eax,%ebx
movsd  0x10(%rsp),%xmm1
movsd  0xe71(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0xe42(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xe2d(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xe18(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xe03(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm0
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xdae(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xdb9(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xda4(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  0xd8f(%rip),%xmm1
call   1060 <shubert@plt>
minsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  0xd67(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0x1,%ebp
cmp    $0x9,%ebp
je     130a <main+0x1ca>
movsd  %xmm0,(%rsp)
test   %ebx,%ebx
jne    1180 <main+0x40>
cmp    $0x1,%ebp
jne    1180 <main+0x40>
xor    %eax,%eax
call   1050 <omp_get_num_threads@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1180 <main+0x40>
lea    0xd63(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [20 x i8] c"Thread #%d, i = %d\0A\00"
@.str.2 = [19 x i8] c"Global min = %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store i32 0, i32* %1
store i32 8, i32* %2
store i32 -2, i32* %3
store double 5.000000e-01, double* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store double 0.000000e+00, double* %10
store double 9.900000e+01, double* %11
store i32 0, i32* %7
br label %12
12: ; preds = %55, %0
%13 = load i32, i32* %7
%14 = icmp sle i32 %13, 8
br i1 %14, label %15, label %58
15: ; preds = %12
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = call i32 (...) @omp_get_num_threads()
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = sitofp i32 %23 to double
%25 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %24)
br label %26
26: ; preds = %21, %18, %15
%27 = call i32 (...) @omp_get_thread_num()
store i32 %27, i32* %6
%28 = load i32, i32* %7
%29 = sitofp i32 %28 to double
%30 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %29, double -2.000000e+00)
store double %30, double* %8
%31 = load i32, i32* %6
%32 = sitofp i32 %31 to double
%33 = load i32, i32* %7
%34 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %32, i32 %33)
store double -2.000000e+00, double* %9
br label %35
35: ; preds = %51, %26
%36 = load double, double* %9
%37 = fcmp ole double %36, 2.000000e+00
br i1 %37, label %38, label %54
38: ; preds = %35
%39 = load double, double* %8
%40 = load double, double* %9
%41 = call double @shubert(double %39, double %40)
store double %41, double* %10
%42 = load double, double* %10
%43 = load double, double* %11
%44 = fcmp olt double %42, %43
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = load double, double* %10
br label %49
47: ; preds = %38
%48 = load double, double* %11
br label %49
49: ; preds = %47, %45
%50 = phi double [ %46, %45 ], [ %48, %47 ]
store double %50, double* %11
br label %51
51: ; preds = %49
%52 = load double, double* %9
%53 = fadd double %52, 5.000000e-01
store double %53, double* %9
br label %35
54: ; preds = %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %12
58: ; preds = %12
%59 = load double, double* %11
%60 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %59)
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [24 x i8] c"Number of threads = %d\0A\00"
@.str.1 = [20 x i8] c"Thread #%d, i = %d\0A\00"
@.str.2 = [19 x i8] c"Global min = %.2f\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %12
%2 = phi double [ 9.900000e+01, %0 ], [ %44, %12 ]
%3 = phi i32 [ 0, %0 ], [ %45, %12 ]
%4 = phi i32 [ 0, %0 ], [ %13, %12 ]
%5 = icmp eq i32 %4, 0
%6 = icmp eq i32 %3, 1
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = tail call i32 (...) @omp_get_num_threads()
%10 = sitofp i32 %9 to double
%11 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), double %10)
br label %12
12: ; preds = %8, %1
%13 = tail call i32 (...) @omp_get_thread_num()
%14 = sitofp i32 %3 to double
%15 = tail call double @llvm.fmuladd.f64(double %14, double 5.000000e-01, double -2.000000e+00)
%16 = sitofp i32 %13 to double
%17 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), double %16, i32 %3)
%18 = tail call double @shubert(double %15, double -2.000000e+00)
%19 = fcmp olt double %18, %2
%20 = select i1 %19, double %18, double %2
%21 = tail call double @shubert(double %15, double -1.500000e+00)
%22 = fcmp olt double %21, %20
%23 = select i1 %22, double %21, double %20
%24 = tail call double @shubert(double %15, double -1.000000e+00)
%25 = fcmp olt double %24, %23
%26 = select i1 %25, double %24, double %23
%27 = tail call double @shubert(double %15, double -5.000000e-01)
%28 = fcmp olt double %27, %26
%29 = select i1 %28, double %27, double %26
%30 = tail call double @shubert(double %15, double 0.000000e+00)
%31 = fcmp olt double %30, %29
%32 = select i1 %31, double %30, double %29
%33 = tail call double @shubert(double %15, double 5.000000e-01)
%34 = fcmp olt double %33, %32
%35 = select i1 %34, double %33, double %32
%36 = tail call double @shubert(double %15, double 1.000000e+00)
%37 = fcmp olt double %36, %35
%38 = select i1 %37, double %36, double %35
%39 = tail call double @shubert(double %15, double 1.500000e+00)
%40 = fcmp olt double %39, %38
%41 = select i1 %40, double %39, double %38
%42 = tail call double @shubert(double %15, double 2.000000e+00)
%43 = fcmp olt double %42, %41
%44 = select i1 %43, double %42, double %41
%45 = add nuw nsw i32 %3, 1
%46 = icmp eq i32 %45, 9
br i1 %46, label %47, label %1
47: ; preds = %12
%48 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %44)
ret i32 0
}