#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 look_for_symbol(void *, char *);
int detect_openmp(void *handle) {
  int i = 0;
  int found = 0;
  char *openmp_symbols[3] = {"_xlsmpParallelDoSetup_TPO", "__kmpc_fork_call",
                             "GOMP_parallel_start"};
  while ((i < 3) && (!found)) {
    found = look_for_symbol(handle, openmp_symbols[i]);
    i++;
  }
  return found;
}


x86 assembly (clang, -O0):
<detect_openmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2ccf(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ccc(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cc9(%rip),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0xc(%rbp)
mov    %al,-0x31(%rbp)
jge    1166 <detect_openmp+0x56>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1176 <detect_openmp+0x66>
jmp    1199 <detect_openmp+0x89>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
call   1030 <look_for_symbol@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114b <detect_openmp+0x3b>
mov    -0x10(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_openmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xf1e(%rip),%r14
xor    %r12d,%r12d
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
movslq (%rbx),%rsi
add    %r14,%rsi
mov    %r15,%rdi
call   1030 <look_for_symbol@plt>
cmp    $0x1,%r12
ja     1150 <detect_openmp+0x40>
add    $0x1,%r12
add    $0x4,%rbx
test   %eax,%eax
je     1130 <detect_openmp+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [26 x i8] c"_xlsmpParallelDoSetup_TPO\00"
@.str.1 = [17 x i8] c"__kmpc_fork_call\00"
@.str.2 = [20 x i8] c"GOMP_parallel_start\00"
@__const.detect_openmp.openmp_symbols = [3 x i8*] [i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i32 0, i32 0)]
define i32 @detect_openmp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [3 x i8*]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = bitcast [3 x i8*]* %5 to i8*
br label %7
7: ; preds = %16, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br label %14
14: ; preds = %10, %7
%15 = phi i1 [ false, %7 ], [ %13, %10 ]
br i1 %15, label %16, label %25
16: ; preds = %14
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @look_for_symbol(i8* %17, i8* %21)
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %7
25: ; preds = %14
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [26 x i8] c"_xlsmpParallelDoSetup_TPO\00"
@.str.1 = [17 x i8] c"__kmpc_fork_call\00"
@.str.2 = [20 x i8] c"GOMP_parallel_start\00"
@reltable.detect_openmp = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.detect_openmp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.detect_openmp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.detect_openmp to i64)) to i32)]
define i32 @detect_openmp(i8* %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i64 [ 0, %1 ], [ %7, %2 ]
%4 = shl i64 %3, 2
%5 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.detect_openmp to i8*), i64 %4)
%6 = tail call i32 @look_for_symbol(i8* %0, i8* %5)
%7 = add nuw nsw i64 %3, 1
%8 = icmp ult i64 %3, 2
%9 = icmp eq i32 %6, 0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %2, label %11
11: ; preds = %2
ret i32 %6
}