#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 /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ opts;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(void *);
int init_module(void *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
void *read_file(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int insmod_main(int argc, char **argv) {
  void *file;
  ssize_t size = 0;
  char opts[1024];
  int ret;
  if (argc < 2) {
    fprintf(stderr, "usage: insmod <module.o>\n");
    return -1;
  }
  file = read_file(argv[1], &size);
  if (!file) {
    fprintf(stderr, "insmod: can't open '%s'\n", argv[1]);
    return -1;
  }
  opts[0] = '\0';
  if (argc > 2) {
    int i, len;
    char *end = opts + sizeof(opts) - 1;
    char *ptr = opts;
    for (i = 2; (i < argc) && (ptr < end); i++) {
      len = ((strlen(argv[i])) < (end - ptr) ? (strlen(argv[i])) : (end - ptr));
      memcpy(ptr, argv[i], len);
      ptr += len;
      *ptr++ = ' ';
    }
    *(ptr - 1) = '\0';
  }
  ret = init_module(file, size, opts);
  if (ret != 0) {
    fprintf(stderr, "insmod: init_module '%s' failed (%s)\n", argv[1],
            strerror(errno));
  }
  free(file);
  return ret;
}


x86 assembly (clang, -O0):
<insmod_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b6 <insmod_main+0x46>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ee <insmod_main+0x27e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <read_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1201 <insmod_main+0x91>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ee <insmod_main+0x27e>
movb   $0x0,-0x420(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    136c <insmod_main+0x1fc>
lea    -0x420(%rbp),%rax
add    $0x400,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
movl   $0x2,-0x428(%rbp)
mov    -0x428(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x441(%rbp)
jge    1270 <insmod_main+0x100>
mov    -0x440(%rbp),%rax
cmp    -0x438(%rbp),%rax
setb   %al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    1283 <insmod_main+0x113>
jmp    1361 <insmod_main+0x1f1>
mov    -0x10(%rbp),%rax
movslq -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
cltq
mov    -0x438(%rbp),%rcx
mov    -0x440(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jge    12d5 <insmod_main+0x165>
mov    -0x10(%rbp),%rax
movslq -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
cltq
mov    %rax,-0x450(%rbp)
jmp    12ed <insmod_main+0x17d>
mov    -0x438(%rbp),%rax
mov    -0x440(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rax
mov    %eax,-0x42c(%rbp)
mov    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x428(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x42c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x42c(%rbp),%ecx
mov    -0x440(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x440(%rbp)
mov    -0x440(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x440(%rbp)
movb   $0x20,(%rax)
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    1242 <insmod_main+0xd2>
mov    -0x440(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x420(%rbp),%rdx
call   1080 <init_module@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
je     13dc <insmod_main+0x26c>
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x458(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rdx
mov    %rax,%rcx
lea    0xc5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insmod_main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
movl   $0x0,0x4(%rsp)
cmp    $0x1,%edi
jg     11aa <insmod_main+0x3a>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12b8 <insmod_main+0x148>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0x4(%rsp),%rsi
call   1070 <read_file@plt>
test   %rax,%rax
je     129d <insmod_main+0x12d>
mov    %rax,%r14
movb   $0x0,0x10(%rsp)
cmp    $0x3,%ebp
jb     124b <insmod_main+0xdb>
mov    %r14,0x8(%rsp)
lea    0x10(%rsp),%rbx
lea    0x40f(%rsp),%r12
mov    %ebp,%r13d
mov    $0x3,%r14d
xchg   %ax,%ax
mov    -0x8(%r15,%r14,8),%rdi
call   1040 <strlen@plt>
cltq
mov    %r12,%rbp
sub    %rbx,%rbp
cmp    %rax,%rbp
jle    1213 <insmod_main+0xa3>
mov    -0x8(%r15,%r14,8),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    -0x8(%r15,%r14,8),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <memcpy@plt>
movslq %ebp,%rcx
lea    (%rbx,%rcx,1),%rax
add    $0x1,%rax
movb   $0x20,(%rbx,%rcx,1)
cmp    %r13,%r14
jae    1242 <insmod_main+0xd2>
add    $0x1,%r14
mov    %rax,%rbx
cmp    %r12,%rax
jb     11f0 <insmod_main+0x80>
movb   $0x0,-0x1(%rax)
mov    0x8(%rsp),%r14
mov    0x4(%rsp),%esi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1080 <init_module@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1293 <insmod_main+0x123>
mov    0x2d77(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%r15),%r15
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdaf(%rip),%rsi
mov    %ebp,%edi
mov    %r15,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    12bd <insmod_main+0x14d>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd69(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"usage: insmod <module.o>\0A\00"
@.str.1 = [25 x i8] c"insmod: can't open '%s'\0A\00"
@.str.2 = [38 x i8] c"insmod: init_module '%s' failed (%s)\0A\00"
@errno = global i32 0
define i32 @insmod_main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %121
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i8* @read_file(i8* %22, i32* %7)
store i8* %23, i8** %6
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %32, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %121
32: ; preds = %19
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8 0, i8* %33
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 2
br i1 %35, label %36, label %102
36: ; preds = %32
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = getelementptr inbounds i8, i8* %37, i64 1024
%39 = getelementptr inbounds i8, i8* %38, i64 -1
store i8* %39, i8** %12
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8* %40, i8** %13
store i32 2, i32* %10
br label %41
41: ; preds = %96, %36
%42 = load i32, i32* %10
%43 = load i32, i32* %4
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i8*, i8** %13
%47 = load i8*, i8** %12
%48 = icmp ult i8* %46, %47
br label %49
49: ; preds = %45, %41
%50 = phi i1 [ false, %41 ], [ %48, %45 ]
br i1 %50, label %51, label %99
51: ; preds = %49
%52 = load i8**, i8*** %5
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @strlen(i8* %56)
%58 = sext i32 %57 to i64
%59 = load i8*, i8** %12
%60 = load i8*, i8** %13
%61 = ptrtoint i8* %59 to i64
%62 = ptrtoint i8* %60 to i64
%63 = sub i64 %61, %62
%64 = icmp slt i64 %58, %63
br i1 %64, label %65, label %73
65: ; preds = %51
%66 = load i8**, i8*** %5
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = call i32 @strlen(i8* %70)
%72 = sext i32 %71 to i64
br label %79
73: ; preds = %51
%74 = load i8*, i8** %12
%75 = load i8*, i8** %13
%76 = ptrtoint i8* %74 to i64
%77 = ptrtoint i8* %75 to i64
%78 = sub i64 %76, %77
br label %79
79: ; preds = %73, %65
%80 = phi i64 [ %72, %65 ], [ %78, %73 ]
%81 = trunc i64 %80 to i32
store i32 %81, i32* %11
%82 = load i8*, i8** %13
%83 = load i8**, i8*** %5
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8*, i8** %83, i64 %85
%87 = load i8*, i8** %86
%88 = load i32, i32* %11
%89 = call i32 @memcpy(i8* %82, i8* %87, i32 %88)
%90 = load i32, i32* %11
%91 = load i8*, i8** %13
%92 = sext i32 %90 to i64
%93 = getelementptr inbounds i8, i8* %91, i64 %92
store i8* %93, i8** %13
%94 = load i8*, i8** %13
%95 = getelementptr inbounds i8, i8* %94, i32 1
store i8* %95, i8** %13
store i8 32, i8* %94
br label %96
96: ; preds = %79
%97 = load i32, i32* %10
%98 = add nsw i32 %97, 1
store i32 %98, i32* %10
br label %41
99: ; preds = %49
%100 = load i8*, i8** %13
%101 = getelementptr inbounds i8, i8* %100, i64 -1
store i8 0, i8* %101
br label %102
102: ; preds = %99, %32
%103 = load i8*, i8** %6
%104 = load i32, i32* %7
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%106 = call i32 @init_module(i8* %103, i32 %104, i8* %105)
store i32 %106, i32* %9
%107 = load i32, i32* %9
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %117
109: ; preds = %102
%110 = load i32, i32* @stderr
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 1
%113 = load i8*, i8** %112
%114 = load i32, i32* @errno
%115 = call i8* @strerror(i32 %114)
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %113, i8* %115)
br label %117
117: ; preds = %109, %102
%118 = load i8*, i8** %6
%119 = call i32 @free(i8* %118)
%120 = load i32, i32* %9
store i32 %120, i32* %3
br label %121
121: ; preds = %117, %26, %16
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"usage: insmod <module.o>\0A\00"
@.str.1 = [25 x i8] c"insmod: can't open '%s'\0A\00"
@.str.2 = [38 x i8] c"insmod: init_module '%s' failed (%s)\0A\00"
@errno = global i32 0
define i32 @insmod_main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %67
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i8* @read_file(i8* %13, i32* %3)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %67
20: ; preds = %11
store i8 0, i8* %6
%21 = icmp ugt i32 %0, 2
br i1 %21, label %22, label %55
22: ; preds = %20
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
%24 = ptrtoint i8* %23 to i64
%25 = zext i32 %0 to i64
br label %26
26: ; preds = %22, %40
%27 = phi i64 [ 2, %22 ], [ %49, %40 ]
%28 = phi i8* [ %6, %22 ], [ %48, %40 ]
%29 = getelementptr inbounds i8*, i8** %1, i64 %27
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = sext i32 %31 to i64
%33 = ptrtoint i8* %28 to i64
%34 = sub i64 %24, %33
%35 = icmp sgt i64 %34, %32
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = load i8*, i8** %29
%38 = call i32 @strlen(i8* %37)
%39 = zext i32 %38 to i64
br label %40
40: ; preds = %26, %36
%41 = phi i64 [ %39, %36 ], [ %34, %26 ]
%42 = trunc i64 %41 to i32
%43 = load i8*, i8** %29
%44 = call i32 @memcpy(i8* %28, i8* %43, i32 %42)
%45 = shl i64 %41, 32
%46 = ashr exact i64 %45, 32
%47 = getelementptr inbounds i8, i8* %28, i64 %46
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8 32, i8* %47
%49 = add nuw nsw i64 %27, 1
%50 = icmp ult i64 %49, %25
%51 = icmp ult i8* %48, %23
%52 = select i1 %50, i1 %51, i1 false
br i1 %52, label %26, label %53
53: ; preds = %40
%54 = getelementptr inbounds i8, i8* %48, i64 -1
store i8 0, i8* %54
br label %55
55: ; preds = %53, %20
%56 = load i32, i32* %3
%57 = call i32 @init_module(i8* %14, i32 %56, i8* %6)
%58 = icmp eq i32 %57, 0
br i1 %58, label %65, label %59
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %12
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %61, i8* %63)
br label %65
65: ; preds = %59, %55
%66 = call i32 @free(i8* %14)
br label %67
67: ; preds = %65, %16, %8
%68 = phi i32 [ -1, %8 ], [ %57, %65 ], [ -1, %16 ]
ret i32 %68
}