#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 rlimit {
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_MEMLOCK;
int /*<<< orphan*/ RLIM_INFINITY;
int atoi(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int test(char *, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
  int opt, num_progs = 1;
  char filename[256];
  while ((opt = getopt(argc, argv, "i:h")) != -1) {
    switch (opt) {
    case 'i':
      num_progs = atoi(optarg);
      break;
    case 'h':
    default:
      usage(argv[0]);
      return 0;
    }
  }
  setrlimit(RLIMIT_MEMLOCK, &r);
  snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
  return test(filename, num_progs);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5a(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     121a <main+0xba>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x124(%rbp)
sub    $0x68,%eax
je     11f8 <main+0x98>
jmp    11ce <main+0x6e>
mov    -0x124(%rbp),%eax
sub    $0x69,%eax
jne    11fd <main+0x9d>
jmp    11e2 <main+0x82>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    1215 <main+0xb5>
jmp    11fd <main+0x9d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    125d <main+0xfd>
jmp    1198 <main+0x38>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <setrlimit@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    $0x100,%esi
lea    0xdbe(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1080 <test@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %eax,0xc(%rsp)
mov    $0x1,%r14d
lea    0xe6e(%rip),%r15
mov    0x2e5f(%rip),%r12
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0x69,%eax
jne    11c0 <main+0x60>
mov    (%r12),%edi
call   1070 <atoi@plt>
mov    %eax,%r14d
jmp    11a0 <main+0x40>
cmp    $0xffffffff,%eax
jne    1201 <main+0xa1>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <setrlimit@plt>
mov    (%rbx),%rcx
lea    0xe22(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <test@plt>
jmp    120b <main+0xab>
mov    (%rbx),%rdi
call   1050 <usage@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIM_INFINITY = global i32 0
@.str = [4 x i8] c"i:h\00"
@optarg = global i32 0
@RLIMIT_MEMLOCK = global i32 0
@.str.1 = [10 x i8] c"%s_kern.o\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%11 = load i32, i32* @RLIM_INFINITY
store i32 %11, i32* %10
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
%13 = load i32, i32* @RLIM_INFINITY
store i32 %13, i32* %12
store i32 1, i32* %8
br label %14
14: ; preds = %30, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %7
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i32, i32* %7
switch i32 %20, label %25 [
i32 105, label %21
i32 104, label %24
]
21: ; preds = %19
%22 = load i32, i32* @optarg
%23 = call i32 @atoi(i32 %22)
store i32 %23, i32* %8
br label %30
24: ; preds = %19
br label %25
25: ; preds = %19, %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @usage(i8* %28)
store i32 0, i32* %3
br label %42
30: ; preds = %21
br label %14
31: ; preds = %14
%32 = load i32, i32* @RLIMIT_MEMLOCK
%33 = call i32 @setrlimit(i32 %32, %struct.rlimit* %6)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @snprintf(i8* %34, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* %8
%41 = call i32 @test(i8* %39, i32 %40)
store i32 %41, i32* %3
br label %42
42: ; preds = %31, %25
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIM_INFINITY = global i32 0
@.str = [4 x i8] c"i:h\00"
@optarg = global i32 0
@RLIMIT_MEMLOCK = global i32 0
@.str.1 = [10 x i8] c"%s_kern.o\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.rlimit
%4 = alloca [256 x i8]
%5 = bitcast %struct.rlimit* %3 to i8*
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
%7 = load i32, i32* @RLIM_INFINITY
store i32 %7, i32* %6
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
br label %10
10: ; preds = %13, %2
%11 = phi i32 [ 1, %2 ], [ %15, %13 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %16 [
i32 -1, label %19
i32 105, label %13
]
13: ; preds = %10
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %10
16: ; preds = %10
%17 = load i8*, i8** %1
%18 = tail call i32 @usage(i8* %17)
br label %25
19: ; preds = %10
%20 = load i32, i32* @RLIMIT_MEMLOCK
%21 = call i32 @setrlimit(i32 %20, %struct.rlimit* %3)
%22 = load i8*, i8** %1
%23 = call i32 @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @test(i8* %9, i32 %11)
br label %25
25: ; preds = %19, %16
%26 = phi i32 [ 0, %16 ], [ %24, %19 ]
ret i32 %26
}