#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 char int8_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_int8(void *handle, const char *fname, int8_t want) {
  int8_t (*fn)();
  fn = (int8_t(*)())dlsym(handle, fname);
  if (!fn) {
    fprintf(stderr, "ERROR: missing %s: %s\n", fname, dlerror());
    return 1;
  }
  signed char 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_int8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <dlsym@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a0 <check_int8+0x70>
mov    0x2e78(%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    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ef <check_int8+0xbf>
mov    $0x0,%al
call   *-0x28(%rbp)
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
je     11e8 <check_int8+0xb8>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
movsbl -0x29(%rbp),%ecx
movsbl -0x19(%rbp),%r8d
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ef <check_int8+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_int8>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
call   1050 <dlsym@plt>
test   %rax,%rax
je     1174 <check_int8+0x44>
mov    %rax,%rcx
xor    %ebx,%ebx
xor    %eax,%eax
call   *%rcx
cmp    %bpl,%al
je     119f <check_int8+0x6f>
movsbl %bpl,%r8d
movsbl %al,%ecx
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    119a <check_int8+0x6a>
mov    0x2e65(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <dlerror@plt>
lea    0xe75(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%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_int8(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8 (...)*
%9 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = call i64 @dlsym(i8* %10, i8* %11)
%13 = inttoptr i64 %12 to i8 (...)*
store i8 (...)* %13, i8 (...)** %8
%14 = load i8 (...)*, i8 (...)** %8
%15 = icmp ne i8 (...)* %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 %38
21: ; preds = %3
%22 = load i8 (...)*, i8 (...)** %8
%23 = call signext i8 (...) %22()
store i8 %23, i8* %9
%24 = load i8, i8* %9
%25 = sext i8 %24 to i32
%26 = load i8, i8* %7
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %37
29: ; preds = %21
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = load i8, i8* %9
%33 = sext i8 %32 to i32
%34 = load i8, i8* %7
%35 = sext i8 %34 to i32
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %31, i32 %33, i32 %35)
store i32 1, i32* %4
br label %38
37: ; preds = %21
store i32 0, i32* %4
br label %38
38: ; preds = %37, %29, %16
%39 = load i32, i32* %4
ret i32 %39
}

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_int8(i8* %0, i8* %1, i8 signext %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 %19
10: ; preds = %3
%11 = inttoptr i64 %4 to i8 (...)*
%12 = tail call signext i8 (...) %11()
%13 = icmp eq i8 %12, %2
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = sext i8 %2 to i32
%16 = sext i8 %12 to i32
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %16, i32 %15)
br label %19
19: ; preds = %14, %10, %6
%20 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 0, %10 ]
ret i32 %20
}