#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_mpi(void *handle) {
  int i = 0;
  int found = 0;
  char *mpi_symbols[10] = {
      "MPI_Init",        "mpi_init",         "mpi_init_",
      "mpi_init__",      "MPI_INIT",         "MPI_Init_thread",
      "mpi_init_thread", "mpi_init_thread_", "mpi_init_thread__",
      "MPI_INIT_THREAD",
  };
  while ((i < 10) && (!found)) {
    found = look_for_symbol(handle, mpi_symbols[i]);
    i++;
  }
  return found;
}


x86 assembly (clang, -O0):
<detect_mpi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2c8b(%rip),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
cmpl   $0xa,-0xc(%rbp)
mov    %al,-0x61(%rbp)
jge    116a <detect_mpi+0x4a>
cmpl   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    117a <detect_mpi+0x5a>
jmp    119d <detect_mpi+0x7d>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
mov    -0x60(%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    114f <detect_mpi+0x2f>
mov    -0x10(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_mpi>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xf62(%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    $0x8,%r12
ja     1150 <detect_mpi+0x40>
add    $0x1,%r12
add    $0x4,%rbx
test   %eax,%eax
je     1130 <detect_mpi+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"MPI_Init\00"
@.str.1 = [9 x i8] c"mpi_init\00"
@.str.2 = [10 x i8] c"mpi_init_\00"
@.str.3 = [11 x i8] c"mpi_init__\00"
@.str.4 = [9 x i8] c"MPI_INIT\00"
@.str.5 = [16 x i8] c"MPI_Init_thread\00"
@.str.6 = [16 x i8] c"mpi_init_thread\00"
@.str.7 = [17 x i8] c"mpi_init_thread_\00"
@.str.8 = [18 x i8] c"mpi_init_thread__\00"
@.str.9 = [16 x i8] c"MPI_INIT_THREAD\00"
@__const.detect_mpi.mpi_symbols = [10 x i8*] [i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i32 0, i32 0)]
define i32 @detect_mpi(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [10 x i8*]
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = bitcast [10 x i8*]* %5 to i8*
br label %7
7: ; preds = %16, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
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 [10 x i8*], [10 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 = [9 x i8] c"MPI_Init\00"
@.str.1 = [9 x i8] c"mpi_init\00"
@.str.2 = [10 x i8] c"mpi_init_\00"
@.str.3 = [11 x i8] c"mpi_init__\00"
@.str.4 = [9 x i8] c"MPI_INIT\00"
@.str.5 = [16 x i8] c"MPI_Init_thread\00"
@.str.6 = [16 x i8] c"mpi_init_thread\00"
@.str.7 = [17 x i8] c"mpi_init_thread_\00"
@.str.8 = [18 x i8] c"mpi_init_thread__\00"
@.str.9 = [16 x i8] c"MPI_INIT_THREAD\00"
@reltable.detect_mpi = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.detect_mpi to i64)) to i32)]
define i32 @detect_mpi(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 ([10 x i32]* @reltable.detect_mpi 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, 9
%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
}