#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++ = '\0';
    }
    *(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    1406 <insmod_main+0x296>
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    1406 <insmod_main+0x296>
movb   $0x0,-0x420(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1384 <insmod_main+0x214>
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    1379 <insmod_main+0x209>
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    -0x440(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x440(%rbp)
movb   $0x0,(%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     13f4 <insmod_main+0x284>
mov    0x2c2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x45c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x458(%rbp)
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rdx
mov    %rax,%rcx
lea    0xc46(%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    12b6 <insmod_main+0x146>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0x4(%rsp),%rsi
call   1070 <read_file@plt>
test   %rax,%rax
je     129b <insmod_main+0x12b>
mov    %rax,%r14
movb   $0x0,0x10(%rsp)
cmp    $0x3,%ebp
jb     1249 <insmod_main+0xd9>
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,%rax
movw   $0x20,(%rbx,%rax,1)
add    %rax,%rbx
add    $0x2,%rbx
cmp    %r13,%r14
jae    1240 <insmod_main+0xd0>
add    $0x1,%r14
cmp    %r12,%rbx
jb     11f0 <insmod_main+0x80>
movb   $0x0,-0x1(%rbx)
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     1291 <insmod_main+0x121>
mov    0x2d79(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%r15),%r15
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdb1(%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    12bb <insmod_main+0x14b>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r15),%rdx
lea    0xd6b(%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 %123
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 %123
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 %104
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 = %98, %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 %101
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
%96 = load i8*, i8** %13
%97 = getelementptr inbounds i8, i8* %96, i32 1
store i8* %97, i8** %13
store i8 0, i8* %96
br label %98
98: ; preds = %79
%99 = load i32, i32* %10
%100 = add nsw i32 %99, 1
store i32 %100, i32* %10
br label %41
101: ; preds = %49
%102 = load i8*, i8** %13
%103 = getelementptr inbounds i8, i8* %102, i64 -1
store i8 0, i8* %103
br label %104
104: ; preds = %101, %32
%105 = load i8*, i8** %6
%106 = load i32, i32* %7
%107 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%108 = call i32 @init_module(i8* %105, i32 %106, i8* %107)
store i32 %108, i32* %9
%109 = load i32, i32* %9
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %119
111: ; preds = %104
%112 = load i32, i32* @stderr
%113 = load i8**, i8*** %5
%114 = getelementptr inbounds i8*, i8** %113, i64 1
%115 = load i8*, i8** %114
%116 = load i32, i32* @errno
%117 = call i8* @strerror(i32 %116)
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %115, i8* %117)
br label %119
119: ; preds = %111, %104
%120 = load i8*, i8** %6
%121 = call i32 @free(i8* %120)
%122 = load i32, i32* %9
store i32 %122, i32* %3
br label %123
123: ; preds = %119, %26, %16
%124 = load i32, i32* %3
ret i32 %124
}

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 %68
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 %68
20: ; preds = %11
store i8 0, i8* %6
%21 = icmp ugt i32 %0, 2
br i1 %21, label %22, label %56
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 ], [ %50, %40 ]
%28 = phi i8* [ %6, %22 ], [ %49, %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 = getelementptr inbounds i8, i8* %48, i64 1
store i8 0, i8* %48
%50 = add nuw nsw i64 %27, 1
%51 = icmp ult i64 %50, %25
%52 = icmp ult i8* %49, %23
%53 = select i1 %51, i1 %52, i1 false
br i1 %53, label %26, label %54
54: ; preds = %40
%55 = getelementptr inbounds i8, i8* %49, i64 -1
store i8 0, i8* %55
br label %56
56: ; preds = %54, %20
%57 = load i32, i32* %3
%58 = call i32 @init_module(i8* %14, i32 %57, i8* %6)
%59 = icmp eq i32 %58, 0
br i1 %59, label %66, label %60
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %12
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* %64)
br label %66
66: ; preds = %60, %56
%67 = call i32 @free(i8* %14)
br label %68
68: ; preds = %66, %16, %8
%69 = phi i32 [ -1, %8 ], [ %58, %66 ], [ -1, %16 ]
ret i32 %69
}