#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 */
typedef int int32_t;

/* Variables and functions */
char *dlerror();
scalar_t__ dlsym(void *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
int check_int32(void *handle, const char *fname, int32_t want) {
  int32_t (*fn)();
  fn = (int32_t(*)())dlsym(handle, fname);
  if (!fn) {
    fprintf(stderr, "ERROR: missing %s: %s\n", fname, dlerror());
    return 1;
  }
  int32_t ret = fn();
  if (ret != want) {
    fprintf(stderr, "ERROR: %s=%d, want %d\n", fname, ret, want);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_int32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119e <check_int32+0x6e>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <dlerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xe75(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <check_int32+0xb7>
mov    $0x0,%al
call   *-0x28(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11e0 <check_int32+0xb0>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <check_int32+0xb7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_int32>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
call   1050 <dlsym@plt>
test   %rax,%rax
je     1173 <check_int32+0x43>
mov    %rax,%rcx
xor    %ebp,%ebp
xor    %eax,%eax
call   *%rcx
cmp    %r14d,%eax
je     119e <check_int32+0x6e>
mov    0x2e87(%rip),%rcx
mov    (%rcx),%edi
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1199 <check_int32+0x69>
mov    0x2e66(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe76(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"ERROR: missing %s: %s\0A\00"
@.str.1 = [23 x i8] c"ERROR: %s=%d, want %d\0A\00"
define i32 @check_int32(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32 (...)*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i64 @dlsym(i8* %10, i8* %11)
%13 = inttoptr i64 %12 to i32 (...)*
store i32 (...)* %13, i32 (...)** %8
%14 = load i32 (...)*, i32 (...)** %8
%15 = icmp ne i32 (...)* %14, null
br i1 %15, label %21, label %16
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %6
%19 = call i8* (...) @dlerror()
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
store i32 1, i32* %4
br label %34
21: ; preds = %3
%22 = load i32 (...)*, i32 (...)** %8
%23 = call i32 (...) %22()
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %6
%30 = load i32, i32* %9
%31 = load i32, i32* %7
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %30, i32 %31)
store i32 1, i32* %4
br label %34
33: ; preds = %21
store i32 0, i32* %4
br label %34
34: ; preds = %33, %27, %16
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"ERROR: missing %s: %s\0A\00"
@.str.1 = [23 x i8] c"ERROR: %s=%d, want %d\0A\00"
define i32 @check_int32(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @dlsym(i8* %0, i8* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i8* (...) @dlerror()
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %8)
br label %17
10: ; preds = %3
%11 = inttoptr i64 %4 to i32 (...)*
%12 = tail call i32 (...) %11()
%13 = icmp eq i32 %12, %2
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %12, i32 %2)
br label %17
17: ; preds = %14, %10, %6
%18 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %10 ]
ret i32 %18
}