#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(void *);
long init_module(void *, unsigned long, char *);
int /*<<< orphan*/ moderror(int /*<<< orphan*/);
void *module_image_size(char *, unsigned long *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  unsigned int i;
  long int ret;
  unsigned long len;
  void *file;
  char *filename, *options = strdup("");
  char *progname = argv[0];
  if (!options) {
    fprintf(stderr, "insmod: can't allocate memory: %s\n", strerror(errno));
    exit(1);
  }
  filename = argv[1];
  for (i = 2; i < argc; i++) {
    options = realloc(options, strlen(options) + 1 + strlen(argv[i]) + 1);
    if (!options) {
      fprintf(stderr, "insmod: can't allocate memory: %s\n", strerror(errno));
      exit(1);
    }
    strcat(options, argv[i]);
    strcat(options, " ");
  }
  file = module_image_size(filename, &len);
  if (!file) {
    fprintf(stderr, "insmod: can't read '%s': %s\n", filename, strerror(errno));
    exit(1);
  }
  ret = init_module(file, len, options);
  if (ret != 0) {
    fprintf(stderr, "insmod: error inserting '%s': %li %s\n", filename, ret,
            moderror(errno));
  }
  free(file);
  if (ret != 0)
    exit(1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe71(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1227 <main+0x77>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    12fc <main+0x14c>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1090 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12ca <main+0x11a>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xd47(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xd3a(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123a <main+0x8a>
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <module_image_size@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    135c <main+0x1ac>
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1080 <init_module@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     13ce <main+0x21e>
mov    0x2c5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   1060 <moderror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    %eax,%r8d
lea    0xc7b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     13ec <main+0x23c>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xe77(%rip),%rdi
call   10c0 <strdup@plt>
test   %rax,%rax
jne    1208 <main+0x58>
mov    0x2e05(%rip),%rax
mov    (%rax),%ebx
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xe0e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r13
mov    0x8(%r15),%rax
mov    %rax,0x8(%rsp)
cmp    $0x3,%ebx
jb     1286 <main+0xd6>
mov    %ebx,%r14d
mov    $0x2,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    (%r15,%r12,8),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%rsi
add    $0x2,%rsi
mov    %r13,%rdi
call   1090 <realloc@plt>
test   %rax,%rax
je     11d4 <main+0x24>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %r13,%rdi
lea    0xdab(%rip),%rsi
call   10a0 <strcat@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    1230 <main+0x80>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <module_image_size@plt>
test   %rax,%rax
jne    12d4 <main+0x124>
mov    0x2d3c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd6a(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rsi
mov    %rax,%rdi
mov    %r13,%rdx
call   1080 <init_module@plt>
test   %rax,%rax
jne    12fb <main+0x14b>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    %rax,%rbx
mov    0x2cdb(%rip),%rax
mov    (%rax),%r14d
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1060 <moderror@plt>
lea    0xd25(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [35 x i8] c"insmod: can't allocate memory: %s\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [29 x i8] c"insmod: can't read '%s': %s\0A\00"
@.str.4 = [38 x i8] c"insmod: error inserting '%s': %li %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %11
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
store i8* %16, i8** %12
%17 = load i8*, i8** %11
%18 = icmp ne i8* %17, null
br i1 %18, label %25, label %19
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %10
store i32 2, i32* %6
br label %29
29: ; preds = %65, %25
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp ult i32 %30, %31
br i1 %32, label %33, label %68
33: ; preds = %29
%34 = load i8*, i8** %11
%35 = load i8*, i8** %11
%36 = call i64 @strlen(i8* %35)
%37 = add nsw i64 %36, 1
%38 = load i8**, i8*** %5
%39 = load i32, i32* %6
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @strlen(i8* %42)
%44 = add nsw i64 %37, %43
%45 = add nsw i64 %44, 1
%46 = call i8* @realloc(i8* %34, i64 %45)
store i8* %46, i8** %11
%47 = load i8*, i8** %11
%48 = icmp ne i8* %47, null
br i1 %48, label %55, label %49
49: ; preds = %33
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %33
%56 = load i8*, i8** %11
%57 = load i8**, i8*** %5
%58 = load i32, i32* %6
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 @strcat(i8* %56, i8* %61)
%63 = load i8*, i8** %11
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %65
65: ; preds = %55
%66 = load i32, i32* %6
%67 = add i32 %66, 1
store i32 %67, i32* %6
br label %29
68: ; preds = %29
%69 = load i8*, i8** %10
%70 = call i8* @module_image_size(i8* %69, i64* %8)
store i8* %70, i8** %9
%71 = load i8*, i8** %9
%72 = icmp ne i8* %71, null
br i1 %72, label %80, label %73
73: ; preds = %68
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %10
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %68
%81 = load i8*, i8** %9
%82 = load i64, i64* %8
%83 = load i8*, i8** %11
%84 = call i64 @init_module(i8* %81, i64 %82, i8* %83)
store i64 %84, i64* %7
%85 = load i64, i64* %7
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %80
%88 = load i32, i32* @stderr
%89 = load i8*, i8** %10
%90 = load i64, i64* %7
%91 = load i32, i32* @errno
%92 = call i32 @moderror(i32 %91)
%93 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %89, i64 %90, i32 %92)
br label %94
94: ; preds = %87, %80
%95 = load i8*, i8** %9
%96 = call i32 @free(i8* %95)
%97 = load i64, i64* %7
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %94
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %94
%102 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [35 x i8] c"insmod: can't allocate memory: %s\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c" \00"
@.str.3 = [29 x i8] c"insmod: can't read '%s': %s\0A\00"
@.str.4 = [38 x i8] c"insmod: error inserting '%s': %li %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = icmp ugt i32 %0, 2
br i1 %16, label %17, label %41
17: ; preds = %13
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %17, %36
%20 = phi i64 [ 2, %17 ], [ %39, %36 ]
%21 = phi i8* [ %5, %17 ], [ %28, %36 ]
%22 = tail call i64 @strlen(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 %20
%24 = load i8*, i8** %23
%25 = tail call i64 @strlen(i8* dereferenceable(1) %24)
%26 = add i64 %22, 2
%27 = add i64 %26, %25
%28 = tail call i8* @realloc(i8* %21, i64 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %36
30: ; preds = %19
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %19
%37 = tail call i32 @strcat(i8* %28, i8* %24)
%38 = tail call i32 @strcat(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = add nuw nsw i64 %20, 1
%40 = icmp eq i64 %39, %18
br i1 %40, label %41, label %19
41: ; preds = %36, %13
%42 = phi i8* [ %5, %13 ], [ %28, %36 ]
%43 = call i8* @module_image_size(i8* %15, i64* %3)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
%52 = load i64, i64* %3
%53 = call i64 @init_module(i8* %43, i64 %52, i8* %42)
%54 = icmp eq i64 %53, 0
br i1 %54, label %62, label %55
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i32 @moderror(i32 %57)
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %15, i64 %53, i32 %58)
%60 = call i32 @free(i8* %43)
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %51
%63 = call i32 @free(i8* %43)
%64 = call i32 @exit(i32 0)
unreachable
}