#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 */
struct module {
  int dummy;
};

/* Variables and functions */
struct module *module_load(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ module_unload(struct module *);
int /*<<< orphan*/ printf(char *);
int main() {
  struct module *mod;
  mod = module_load("missing_module_name.o", 0, 0);
  if (mod) {
    printf("ERROR: Loaded non-existing module.\n");
    return 1;
  }
  module_unload(mod);
  printf("OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <module_load@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <main+0x46>
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1192 <main+0x62>
mov    -0x10(%rbp),%rdi
call   1050 <module_unload@plt>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1040 <module_load@plt>
test   %rax,%rax
je     1156 <main+0x26>
mov    $0x1,%ebx
lea    0xec5(%rip),%rdi
jmp    1164 <main+0x34>
xor    %edi,%edi
call   1050 <module_unload@plt>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.module = type { i32 }
@.str = [22 x i8] c"missing_module_name.o\00"
@.str.1 = [36 x i8] c"ERROR: Loaded non-existing module.\0A\00"
@.str.2 = [4 x i8] c"OK\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.module*
store i32 0, i32* %1
%3 = call %struct.module* @module_load(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
store %struct.module* %3, %struct.module** %2
%4 = load %struct.module*, %struct.module** %2
%5 = icmp ne %struct.module* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %12
8: ; preds = %0
%9 = load %struct.module*, %struct.module** %2
%10 = call i32 @module_unload(%struct.module* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %12
12: ; preds = %8, %6
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
%struct.module = type { i32 }
@.str = [22 x i8] c"missing_module_name.o\00"
@str = [3 x i8] c"OK\00"
@str.3 = [35 x i8] c"ERROR: Loaded non-existing module.\00"
define i32 @main() {
%1 = tail call %struct.module* @module_load(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%2 = icmp eq %struct.module* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @module_unload(%struct.module* null)
br label %5
5: ; preds = %0, %3
%6 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.3, i64 0, i64 0), %0 ]
%7 = phi i32 [ 0, %3 ], [ 1, %0 ]
%8 = tail call i32 @puts(i8* dereferenceable(1) %6)
ret i32 %7
}