#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 stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int PROT_READ;
int PROT_WRITE;
int atoi(char *);
int /*<<< orphan*/ errno;
char *extractModule(char *, char *, int, int *);
int /*<<< orphan*/ free(char *);
int init_module(void *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ logMessage(int, char *, char *, ...);
char *malloc(scalar_t__);
void *mmap(int /*<<< orphan*/, int /*<<< orphan*/, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int usage();
int ourInsmodCommand(int argc, char **argv) {
  char *file;
  int rc, rmObj = 0;
  char *ballPath = NULL;
  int version = 1;
  int fd;
  void *modbuf = NULL;
  struct stat sb;
  if (argc < 2) {
    return usage();
  }
  while (argc > 2) {
    if (!strcmp(argv[1], "-p")) {
      ballPath = malloc(strlen(argv[2]) + 30);
      sprintf(ballPath, "%s/modules.cgz", argv[2]);
      argv += 2;
      argc -= 2;
    } else if (!strcmp(argv[1], "--modballversion")) {
      version = atoi(argv[2]);
      argv += 2;
      argc -= 2;
    } else if (!strncmp(argv[1], "-", 1)) {
      argc -= 1;
      argv += 1;
    } else {
      break;
    }
  }
  if (!ballPath) {
    ballPath = strdup("/modules/modules.cgz");
  }
  file = extractModule(argv[1], ballPath, version, &rmObj);
  free(ballPath);
  if (file == NULL)
    return 1;
  if (stat(file, &sb) == -1) {
    logMessage(40, "unable to stat file %s: %s", file, strerror(errno));
    return 1;
  }
  fd = open(file, O_RDONLY);
  if (fd < 0) {
    logMessage(40, "unable to open file %s: %s", file, strerror(errno));
    return 1;
  }
  modbuf = mmap(0, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
  if (modbuf == NULL) {
    logMessage(40, "error reading file %s: %s", file, strerror(errno));
    return 1;
  }
  if (argc > 2) {
    rc = init_module(modbuf, sb.st_size, argv[2]);
  } else {
    rc = init_module(modbuf, sb.st_size, "");
  }
  if (rc != 0)
    logMessage(30, "failed to insert module (%d)", errno);
  return rc;
}


x86 assembly (clang, -O0):
<ourInsmodCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1246 <ourInsmodCommand+0x46>
mov    $0x0,%al
call   10c0 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    153a <ourInsmodCommand+0x33a>
jmp    124b <ourInsmodCommand+0x4b>
cmpl   $0x2,-0x8(%rbp)
jle    1358 <ourInsmodCommand+0x158>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12c1 <ourInsmodCommand+0xc1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x1e,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd61(%rip),%rsi
call   10f0 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    1353 <ourInsmodCommand+0x153>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd42(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1308 <ourInsmodCommand+0x108>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    134e <ourInsmodCommand+0x14e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd0c(%rip),%rsi
mov    $0x1,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    1344 <ourInsmodCommand+0x144>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1349 <ourInsmodCommand+0x149>
jmp    1358 <ourInsmodCommand+0x158>
jmp    134e <ourInsmodCommand+0x14e>
jmp    1353 <ourInsmodCommand+0x153>
jmp    124b <ourInsmodCommand+0x4b>
cmpq   $0x0,-0x28(%rbp)
jne    1373 <ourInsmodCommand+0x173>
lea    0xcbb(%rip),%rdi
call   1100 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1120 <extractModule@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
cmpq   $0x0,-0x18(%rbp)
jne    13af <ourInsmodCommand+0x1af>
movl   $0x1,-0x4(%rbp)
jmp    153a <ourInsmodCommand+0x33a>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    1400 <ourInsmodCommand+0x200>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
mov    $0x28,%edi
lea    0xc4d(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
movl   $0x1,-0x4(%rbp)
jmp    153a <ourInsmodCommand+0x33a>
mov    -0x18(%rbp),%rdi
mov    0x2bd5(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    145a <ourInsmodCommand+0x25a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
mov    $0x28,%edi
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
movl   $0x1,-0x4(%rbp)
jmp    153a <ourInsmodCommand+0x33a>
mov    -0x40(%rbp),%esi
mov    0x2b94(%rip),%rax
mov    (%rax),%edx
mov    0x2b5b(%rip),%rax
or     (%rax),%edx
mov    0x2b4a(%rip),%rax
mov    (%rax),%ecx
mov    -0x30(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1070 <mmap@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    14d1 <ourInsmodCommand+0x2d1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2b2b(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
mov    $0x28,%edi
lea    0xbb2(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
movl   $0x1,-0x4(%rbp)
jmp    153a <ourInsmodCommand+0x33a>
cmpl   $0x2,-0x8(%rbp)
jle    14f7 <ourInsmodCommand+0x2f7>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
call   10b0 <init_module@plt>
mov    %eax,-0x1c(%rbp)
jmp    150d <ourInsmodCommand+0x30d>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%esi
lea    0xba1(%rip),%rdx
call   10b0 <init_module@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1534 <ourInsmodCommand+0x334>
mov    0x2ab2(%rip),%rax
movslq (%rax),%rdx
mov    $0x1e,%edi
lea    0xb5d(%rip),%rsi
mov    $0x0,%al
call   1030 <logMessage@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ourInsmodCommand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x14(%rsp)
cmp    $0x2,%edi
jge    1230 <ourInsmodCommand+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <usage@plt>
mov    %rsi,%r13
jne    1241 <ourInsmodCommand+0x41>
mov    $0x1,%ebp
xor    %ebx,%ebx
jmp    1312 <ourInsmodCommand+0x112>
mov    %edi,%ebp
movl   $0x1,0xc(%rsp)
xor    %r15d,%r15d
lea    0xdab(%rip),%r12
jmp    129a <ourInsmodCommand+0x9a>
nopw   0x0(%rax,%rax,1)
mov    0x10(%r13),%rbx
add    $0x10,%r13
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1e(%rax),%rdi
call   10a0 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
lea    0xd7d(%rip),%rsi
mov    %rbx,%rdx
call   10f0 <sprintf@plt>
mov    $0xfffffffe,%eax
add    %eax,%ebp
cmp    $0x2,%ebp
jle    1303 <ourInsmodCommand+0x103>
mov    0x8(%r13),%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1260 <ourInsmodCommand+0x60>
mov    %r14,%rdi
lea    0xd5b(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     12f0 <ourInsmodCommand+0xf0>
mov    %r14,%rdi
lea    0xd59(%rip),%rsi
mov    $0x1,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
jne    1307 <ourInsmodCommand+0x107>
add    $0x8,%r13
mov    $0xffffffff,%eax
jmp    1293 <ourInsmodCommand+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%r13),%rdi
add    $0x10,%r13
call   10e0 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    128e <ourInsmodCommand+0x8e>
xor    %ebx,%ebx
jmp    1309 <ourInsmodCommand+0x109>
mov    $0x1,%bl
test   %r15,%r15
mov    0xc(%rsp),%ebp
jne    1321 <ourInsmodCommand+0x121>
lea    0xd0c(%rip),%rdi
call   1100 <strdup@plt>
mov    %rax,%r15
mov    0x8(%r13),%rdi
lea    0x14(%rsp),%rcx
mov    %r15,%rsi
mov    %ebp,%edx
call   1120 <extractModule@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <free@plt>
mov    $0x1,%r14d
test   %rbp,%rbp
je     1408 <ourInsmodCommand+0x208>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
je     13b4 <ourInsmodCommand+0x1b4>
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10d0 <open@plt>
test   %eax,%eax
js     13cb <ourInsmodCommand+0x1cb>
mov    0x10(%rsp),%r15d
mov    0x2c77(%rip),%rcx
mov    0x2c40(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2c2d(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %r15d,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1070 <mmap@plt>
test   %rax,%rax
je     13e2 <ourInsmodCommand+0x1e2>
test   %bl,%bl
je     141a <ourInsmodCommand+0x21a>
mov    0x10(%r13),%rdx
jmp    1421 <ourInsmodCommand+0x221>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc71(%rip),%rsi
jmp    13f7 <ourInsmodCommand+0x1f7>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc75(%rip),%rsi
jmp    13f7 <ourInsmodCommand+0x1f7>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc79(%rip),%rsi
mov    $0x28,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <logMessage@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc85(%rip),%rdx
mov    %rax,%rdi
mov    %r15d,%esi
call   10b0 <init_module@plt>
test   %eax,%eax
je     1452 <ourInsmodCommand+0x252>
mov    %eax,%r14d
mov    0x2b96(%rip),%rax
movslq (%rax),%rdx
lea    0xc46(%rip),%rsi
mov    $0x1e,%edi
xor    %eax,%eax
call   1030 <logMessage@plt>
jmp    1408 <ourInsmodCommand+0x208>
xor    %r14d,%r14d
jmp    1408 <ourInsmodCommand+0x208>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"-p\00"
@.str.1 = [15 x i8] c"%s/modules.cgz\00"
@.str.2 = [17 x i8] c"--modballversion\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [21 x i8] c"/modules/modules.cgz\00"
@.str.5 = [27 x i8] c"unable to stat file %s: %s\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.6 = [27 x i8] c"unable to open file %s: %s\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.7 = [26 x i8] c"error reading file %s: %s\00"
@.str.8 = [1 x i8] zeroinitializer
@.str.9 = [29 x i8] c"failed to insert module (%d)\00"
define i32 @ourInsmodCommand(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca %struct.stat
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i8* null, i8** %9
store i32 1, i32* %10
store i8* null, i8** %12
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 (...) @usage()
store i32 %17, i32* %3
br label %153
18: ; preds = %2
br label %19
19: ; preds = %73, %18
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %74
22: ; preds = %19
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %44, label %28
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 30
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
store i8** %41, i8*** %5
%42 = load i32, i32* %4
%43 = sub nsw i32 %42, 2
store i32 %43, i32* %4
br label %73
44: ; preds = %22
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @strcmp(i8* %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp ne i32 %48, 0
br i1 %49, label %59, label %50
50: ; preds = %44
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %10
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
store i8** %56, i8*** %5
%57 = load i32, i32* %4
%58 = sub nsw i32 %57, 2
store i32 %58, i32* %4
br label %72
59: ; preds = %44
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8*, i8** %61
%63 = call i32 @strncmp(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%64 = icmp ne i32 %63, 0
br i1 %64, label %70, label %65
65: ; preds = %59
%66 = load i32, i32* %4
%67 = sub nsw i32 %66, 1
store i32 %67, i32* %4
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
store i8** %69, i8*** %5
br label %71
70: ; preds = %59
br label %74
71: ; preds = %65
br label %72
72: ; preds = %71, %50
br label %73
73: ; preds = %72, %28
br label %19
74: ; preds = %70, %19
%75 = load i8*, i8** %9
%76 = icmp ne i8* %75, null
br i1 %76, label %79, label %77
77: ; preds = %74
%78 = call i8* @strdup(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i8* %78, i8** %9
br label %79
79: ; preds = %77, %74
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i8*, i8** %81
%83 = load i8*, i8** %9
%84 = load i32, i32* %10
%85 = call i8* @extractModule(i8* %82, i8* %83, i32 %84, i32* %8)
store i8* %85, i8** %6
%86 = load i8*, i8** %9
%87 = call i32 @free(i8* %86)
%88 = load i8*, i8** %6
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %91
90: ; preds = %79
store i32 1, i32* %3
br label %153
91: ; preds = %79
%92 = load i8*, i8** %6
%93 = call i32 @stat(i8* %92, %struct.stat* %13)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %100
95: ; preds = %91
%96 = load i8*, i8** %6
%97 = load i32, i32* @errno
%98 = call i32 @strerror(i32 %97)
%99 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %96, i32 %98)
store i32 1, i32* %3
br label %153
100: ; preds = %91
%101 = load i8*, i8** %6
%102 = load i32, i32* @O_RDONLY
%103 = call i32 @open(i8* %101, i32 %102)
store i32 %103, i32* %11
%104 = load i32, i32* %11
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %111
106: ; preds = %100
%107 = load i8*, i8** %6
%108 = load i32, i32* @errno
%109 = call i32 @strerror(i32 %108)
%110 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %107, i32 %109)
store i32 1, i32* %3
br label %153
111: ; preds = %100
%112 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%113 = load i32, i32* %112
%114 = load i32, i32* @PROT_READ
%115 = load i32, i32* @PROT_WRITE
%116 = or i32 %114, %115
%117 = load i32, i32* @MAP_PRIVATE
%118 = load i32, i32* %11
%119 = call i8* @mmap(i32 0, i32 %113, i32 %116, i32 %117, i32 %118, i32 0)
store i8* %119, i8** %12
%120 = load i8*, i8** %12
%121 = icmp eq i8* %120, null
br i1 %121, label %122, label %127
122: ; preds = %111
%123 = load i8*, i8** %6
%124 = load i32, i32* @errno
%125 = call i32 @strerror(i32 %124)
%126 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %123, i32 %125)
store i32 1, i32* %3
br label %153
127: ; preds = %111
%128 = load i32, i32* %4
%129 = icmp sgt i32 %128, 2
br i1 %129, label %130, label %138
130: ; preds = %127
%131 = load i8*, i8** %12
%132 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%133 = load i32, i32* %132
%134 = load i8**, i8*** %5
%135 = getelementptr inbounds i8*, i8** %134, i64 2
%136 = load i8*, i8** %135
%137 = call i32 @init_module(i8* %131, i32 %133, i8* %136)
store i32 %137, i32* %7
br label %143
138: ; preds = %127
%139 = load i8*, i8** %12
%140 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%141 = load i32, i32* %140
%142 = call i32 @init_module(i8* %139, i32 %141, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0))
store i32 %142, i32* %7
br label %143
143: ; preds = %138, %130
%144 = load i32, i32* %7
%145 = icmp ne i32 %144, 0
br i1 %145, label %146, label %151
146: ; preds = %143
%147 = load i32, i32* @errno
%148 = sext i32 %147 to i64
%149 = inttoptr i64 %148 to i8*
%150 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %149)
br label %151
151: ; preds = %146, %143
%152 = load i32, i32* %7
store i32 %152, i32* %3
br label %153
153: ; preds = %151, %122, %106, %95, %90, %16
%154 = load i32, i32* %3
ret i32 %154
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"-p\00"
@.str.1 = [15 x i8] c"%s/modules.cgz\00"
@.str.2 = [17 x i8] c"--modballversion\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [21 x i8] c"/modules/modules.cgz\00"
@.str.5 = [27 x i8] c"unable to stat file %s: %s\00"
@errno = global i32 0
@O_RDONLY = global i32 0
@.str.6 = [27 x i8] c"unable to open file %s: %s\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_PRIVATE = global i32 0
@.str.7 = [26 x i8] c"error reading file %s: %s\00"
@.str.8 = [1 x i8] zeroinitializer
@.str.9 = [29 x i8] c"failed to insert module (%d)\00"
define i32 @ourInsmodCommand(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.stat
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = icmp eq i32 %0, 2
br i1 %9, label %51, label %12
10: ; preds = %2
%11 = tail call i32 (...) @usage()
br label %107
12: ; preds = %8, %38
%13 = phi i32 [ %42, %38 ], [ 1, %8 ]
%14 = phi i8* [ %41, %38 ], [ null, %8 ]
%15 = phi i32 [ %43, %38 ], [ %0, %8 ]
%16 = phi i8** [ %40, %38 ], [ %1, %8 ]
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strcmp(i8* dereferenceable(1) %18, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %12
%22 = getelementptr inbounds i8*, i8** %16, i64 2
%23 = load i8*, i8** %22
%24 = tail call i64 @strlen(i8* dereferenceable(1) %23)
%25 = add nsw i64 %24, 30
%26 = tail call i8* @malloc(i64 %25)
%27 = tail call i32 @sprintf(i8* dereferenceable(1) %26, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %38
28: ; preds = %12
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %18, i8* dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = getelementptr inbounds i8*, i8** %16, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32 @atoi(i8* %33)
br label %38
35: ; preds = %28
%36 = tail call i32 @strncmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %35, %31, %21
%39 = phi i32 [ -2, %31 ], [ -2, %21 ], [ -1, %35 ]
%40 = phi i8** [ %32, %31 ], [ %22, %21 ], [ %17, %35 ]
%41 = phi i8* [ %14, %31 ], [ %26, %21 ], [ %14, %35 ]
%42 = phi i32 [ %34, %31 ], [ %13, %21 ], [ %13, %35 ]
%43 = add nsw i32 %15, %39
%44 = icmp sgt i32 %43, 2
br i1 %44, label %12, label %45
45: ; preds = %38, %35
%46 = phi i8** [ %40, %38 ], [ %16, %35 ]
%47 = phi i8* [ %41, %38 ], [ %14, %35 ]
%48 = phi i32 [ %42, %38 ], [ %13, %35 ]
%49 = phi i1 [ false, %38 ], [ true, %35 ]
%50 = icmp eq i8* %47, null
br i1 %50, label %51, label %56
51: ; preds = %8, %45
%52 = phi i1 [ %49, %45 ], [ false, %8 ]
%53 = phi i32 [ %48, %45 ], [ 1, %8 ]
%54 = phi i8** [ %46, %45 ], [ %1, %8 ]
%55 = tail call dereferenceable_or_null(21) i8* @strdup(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %51, %45
%57 = phi i1 [ %49, %45 ], [ %52, %51 ]
%58 = phi i32 [ %48, %45 ], [ %53, %51 ]
%59 = phi i8** [ %46, %45 ], [ %54, %51 ]
%60 = phi i8* [ %47, %45 ], [ %55, %51 ]
%61 = getelementptr inbounds i8*, i8** %59, i64 1
%62 = load i8*, i8** %61
%63 = call i8* @extractModule(i8* %62, i8* %60, i32 %58, i32* %3)
%64 = call i32 @free(i8* %60)
%65 = icmp eq i8* %63, null
br i1 %65, label %107, label %66
66: ; preds = %56
%67 = call i32 @stat(i8* %63, %struct.stat* %4)
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i32, i32* @errno
%71 = call i32 @strerror(i32 %70)
%72 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %63, i32 %71)
br label %107
73: ; preds = %66
%74 = load i32, i32* @O_RDONLY
%75 = call i32 @open(i8* %63, i32 %74)
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %81
77: ; preds = %73
%78 = load i32, i32* @errno
%79 = call i32 @strerror(i32 %78)
%80 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %63, i32 %79)
br label %107
81: ; preds = %73
%82 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%83 = load i32, i32* %82
%84 = load i32, i32* @PROT_READ
%85 = load i32, i32* @PROT_WRITE
%86 = or i32 %85, %84
%87 = load i32, i32* @MAP_PRIVATE
%88 = call i8* @mmap(i32 0, i32 %83, i32 %86, i32 %87, i32 %75, i32 0)
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %94
90: ; preds = %81
%91 = load i32, i32* @errno
%92 = call i32 @strerror(i32 %91)
%93 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 40, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %63, i32 %92)
br label %107
94: ; preds = %81
br i1 %57, label %95, label %98
95: ; preds = %94
%96 = getelementptr inbounds i8*, i8** %59, i64 2
%97 = load i8*, i8** %96
br label %98
98: ; preds = %94, %95
%99 = phi i8* [ %97, %95 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i64 0, i64 0), %94 ]
%100 = call i32 @init_module(i8* %88, i32 %83, i8* %99)
%101 = icmp eq i32 %100, 0
br i1 %101, label %107, label %102
102: ; preds = %98
%103 = load i32, i32* @errno
%104 = sext i32 %103 to i64
%105 = inttoptr i64 %104 to i8*
%106 = call i32 (i32, i8*, i8*, ...) @logMessage(i32 30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %105)
br label %107
107: ; preds = %98, %102, %56, %90, %77, %69, %10
%108 = phi i32 [ %11, %10 ], [ 1, %69 ], [ 1, %77 ], [ 1, %90 ], [ 1, %56 ], [ %100, %102 ], [ 0, %98 ]
ret i32 %108
}