#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 /*<<< orphan*/ RTLD_LAZY;
int /*<<< orphan*/ dlclose(void *);
void *dlopen(char *, int /*<<< orphan*/);
void *dlsym(void *, char *);
int /*<<< orphan*/ stdout;
int dump_rtas_event_entry(char *data, int len) {
  void *rtas_event;
  void *handle;
  void *(*parse_rtas_event)();
  void (*rtas_print_event)();
  void (*cleanup_rtas_event)();
  handle = dlopen("/usr/lib/librtasevent.so", RTLD_LAZY);
  if (handle == NULL)
    return 1;
  parse_rtas_event = dlsym(handle, "parse_rtas_event");
  if (parse_rtas_event == NULL) {
    dlclose(handle);
    return 1;
  }
  rtas_print_event = dlsym(handle, "rtas_print_event");
  if (rtas_print_event == NULL) {
    dlclose(handle);
    return 1;
  }
  cleanup_rtas_event = dlsym(handle, "cleanup_rtas_event");
  if (cleanup_rtas_event == NULL) {
    dlclose(handle);
    return 1;
  }
  rtas_event = parse_rtas_event(data, len);
  if (rtas_event == NULL) {
    dlclose(handle);
    return 1;
  }
  rtas_print_event(stdout, rtas_event, 0);
  cleanup_rtas_event(rtas_event);
  dlclose(handle);
  return 0;
}


x86 assembly (clang, -O0):
<dump_rtas_event_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1030 <dlopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116f <dump_rtas_event_entry+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    1271 <dump_rtas_event_entry+0x141>
mov    -0x28(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <dlsym@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a3 <dump_rtas_event_entry+0x73>
mov    -0x28(%rbp),%rdi
call   1050 <dlclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <dump_rtas_event_entry+0x141>
mov    -0x28(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <dlsym@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d7 <dump_rtas_event_entry+0xa7>
mov    -0x28(%rbp),%rdi
call   1050 <dlclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <dump_rtas_event_entry+0x141>
mov    -0x28(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1040 <dlsym@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    120b <dump_rtas_event_entry+0xdb>
mov    -0x28(%rbp),%rdi
call   1050 <dlclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <dump_rtas_event_entry+0x141>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x0,%al
call   *%rcx
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123e <dump_rtas_event_entry+0x10e>
mov    -0x28(%rbp),%rdi
call   1050 <dlclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <dump_rtas_event_entry+0x141>
mov    -0x38(%rbp),%rcx
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   *%rcx
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   *%rcx
mov    -0x28(%rbp),%rdi
call   1050 <dlclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_rtas_event_entry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1030 <dlopen@plt>
test   %rax,%rax
je     11e7 <dump_rtas_event_entry+0xb7>
mov    %rax,%rbx
lea    0xeb0(%rip),%rsi
mov    %rax,%rdi
call   1040 <dlsym@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11dd <dump_rtas_event_entry+0xad>
mov    %rax,%r13
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1040 <dlsym@plt>
test   %rax,%rax
je     11dd <dump_rtas_event_entry+0xad>
mov    %rax,%r12
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1040 <dlsym@plt>
test   %rax,%rax
je     11dd <dump_rtas_event_entry+0xad>
mov    %rax,(%rsp)
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   *%r13
test   %rax,%rax
je     11dd <dump_rtas_event_entry+0xad>
mov    %rax,%r14
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   *%r12
mov    %r14,%rdi
xor    %eax,%eax
call   *(%rsp)
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <dlclose@plt>
jmp    11ec <dump_rtas_event_entry+0xbc>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/usr/lib/librtasevent.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [17 x i8] c"parse_rtas_event\00"
@.str.2 = [17 x i8] c"rtas_print_event\00"
@.str.3 = [19 x i8] c"cleanup_rtas_event\00"
@stdout = global i32 0
define i32 @dump_rtas_event_entry(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8* (...)*
%9 = alloca void (...)*
%10 = alloca void (...)*
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i32, i32* @RTLD_LAZY
%12 = call i8* @dlopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 1, i32* %3
br label %64
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = call i8* @dlsym(i8* %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%19 = bitcast i8* %18 to i8* (...)*
store i8* (...)* %19, i8* (...)** %8
%20 = load i8* (...)*, i8* (...)** %8
%21 = icmp eq i8* (...)* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %7
%24 = call i32 @dlclose(i8* %23)
store i32 1, i32* %3
br label %64
25: ; preds = %16
%26 = load i8*, i8** %7
%27 = call i8* @dlsym(i8* %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%28 = bitcast i8* %27 to void (...)*
store void (...)* %28, void (...)** %9
%29 = load void (...)*, void (...)** %9
%30 = icmp eq void (...)* %29, null
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i8*, i8** %7
%33 = call i32 @dlclose(i8* %32)
store i32 1, i32* %3
br label %64
34: ; preds = %25
%35 = load i8*, i8** %7
%36 = call i8* @dlsym(i8* %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%37 = bitcast i8* %36 to void (...)*
store void (...)* %37, void (...)** %10
%38 = load void (...)*, void (...)** %10
%39 = icmp eq void (...)* %38, null
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = load i8*, i8** %7
%42 = call i32 @dlclose(i8* %41)
store i32 1, i32* %3
br label %64
43: ; preds = %34
%44 = load i8* (...)*, i8* (...)** %8
%45 = load i8*, i8** %4
%46 = load i32, i32* %5
%47 = bitcast i8* (...)* %44 to i8* (i8*, i32, ...)*
%48 = call i8* (i8*, i32, ...) %47(i8* %45, i32 %46)
store i8* %48, i8** %6
%49 = load i8*, i8** %6
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = load i8*, i8** %7
%53 = call i32 @dlclose(i8* %52)
store i32 1, i32* %3
br label %64
54: ; preds = %43
%55 = load void (...)*, void (...)** %9
%56 = load i32, i32* @stdout
%57 = load i8*, i8** %6
%58 = bitcast void (...)* %55 to void (i32, i8*, i32, ...)*
%59 = load void (...)*, void (...)** %10
%60 = load i8*, i8** %6
%61 = bitcast void (...)* %59 to void (i8*, ...)*
%62 = load i8*, i8** %7
%63 = call i32 @dlclose(i8* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %54, %51, %40, %31, %22, %15
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [25 x i8] c"/usr/lib/librtasevent.so\00"
@RTLD_LAZY = global i32 0
@.str.1 = [17 x i8] c"parse_rtas_event\00"
@.str.2 = [17 x i8] c"rtas_print_event\00"
@.str.3 = [19 x i8] c"cleanup_rtas_event\00"
@stdout = global i32 0
define i32 @dump_rtas_event_entry(i8* %0, i32 %1) {
%3 = load i32, i32* @RTLD_LAZY
%4 = tail call i8* @dlopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = tail call i8* @dlsym(i8* %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = bitcast i8* %7 to i8* (i8*, i32, ...)*
%17 = tail call i8* (i8*, i32, ...) %16(i8* %0, i32 %1)
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i32, i32* @stdout
%21 = bitcast i8* %10 to void (i32, i8*, i32, ...)*
tail call void (i32, i8*, i32, ...) %21(i32 %20, i8* %17, i32 0)
%22 = bitcast i8* %13 to void (i8*, ...)*
tail call void (i8*, ...) %22(i8* %17)
br label %23
23: ; preds = %15, %12, %9, %6, %19
%24 = phi i32 [ 0, %19 ], [ 1, %6 ], [ 1, %9 ], [ 1, %12 ], [ 1, %15 ]
%25 = tail call i32 @dlclose(i8* %4)
br label %26
26: ; preds = %23, %2
%27 = phi i32 [ 1, %2 ], [ %24, %23 ]
ret i32 %27
}