#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
void *grab_file(char const *, unsigned long *);
long init_module(void *, unsigned long, char *);
int /*<<< orphan*/ moderror(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int insmod(const char *filename) {
  void *file;
  unsigned long len;
  long int ret;
  file = grab_file(filename, &len);
  if (!file) {
    fprintf(stderr, "insmod: can't read '%s': %s\n", filename, strerror(errno));
    return 1;
  }
  ret = init_module(file, len, "");
  if (ret != 0) {
    fprintf(stderr, "insmod: error inserting '%s': %li %s\n", filename, ret,
            moderror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<insmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <grab_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <insmod+0x6e>
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <insmod+0xea>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    0xe4f(%rip),%rdx
call   1060 <init_module@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1233 <insmod+0xe3>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1050 <moderror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <insmod+0xea>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insmod>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
call   1030 <grab_file@plt>
test   %rax,%rax
je     11b8 <insmod+0x68>
mov    0x8(%rsp),%rsi
lea    0xea6(%rip),%rdx
mov    %rax,%rdi
call   1060 <init_module@plt>
test   %rax,%rax
je     11ec <insmod+0x9c>
mov    %rax,%rbx
mov    0x2e53(%rip),%rax
mov    (%rax),%ebp
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1050 <moderror@plt>
lea    0xe79(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11e5 <insmod+0x95>
mov    0x2e21(%rip),%rax
mov    (%rax),%ebx
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe2a(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    11ee <insmod+0x9e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"insmod: can't read '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [38 x i8] c"insmod: error inserting '%s': %li %s\0A\00"
define i32 @insmod(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @grab_file(i8* %7, i64* %5)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %15)
store i32 1, i32* %2
br label %31
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = call i64 @init_module(i8* %18, i64 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i64 %20, i64* %6
%21 = load i64, i64* %6
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %3
%26 = load i64, i64* %6
%27 = load i32, i32* @errno
%28 = call i32 @moderror(i32 %27)
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %25, i64 %26, i32 %28)
store i32 1, i32* %2
br label %31
30: ; preds = %17
store i32 0, i32* %2
br label %31
31: ; preds = %30, %23, %11
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"insmod: can't read '%s': %s\0A\00"
@errno = global i32 0
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [38 x i8] c"insmod: error inserting '%s': %li %s\0A\00"
define i32 @insmod(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i8* @grab_file(i8* %0, i64* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %9)
br label %20
11: ; preds = %1
%12 = load i64, i64* %2
%13 = call i64 @init_module(i8* %4, i64 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i32 @moderror(i32 %17)
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %0, i64 %13, i32 %18)
br label %20
20: ; preds = %11, %15, %6
%21 = phi i32 [ 1, %15 ], [ 1, %6 ], [ 0, %11 ]
ret i32 %21
}