#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ __real_fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *__real_fopen(char *, char *);
int __real_fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int getpid();
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char *);
void getProcCmdLine(int *ac, char **av) {
  int i = 0, pid;
  int length = 0;
  char *inbuf;
  char file[64];
  FILE *infile;
  char *arg_ptr;
  *ac = 0;
  *av = NULL;
  pid = getpid();
  snprintf(file, 64, "/proc/%d/cmdline", pid);
  infile = __real_fopen(file, "r");
  if (infile != NULL) {
    if (!feof(infile)) {
      av[0] = malloc(4096);
      memset(av[0], 0, 4096);
      length = __real_fread(av[0], 1, 4096, infile);
      if (length > 0) {
        arg_ptr = av[0];
        while (*arg_ptr != '\0') {
          if (i != 0) {
            av[i] = arg_ptr;
            printf("%d: %s\n", i, arg_ptr);
          }
          if ((arg_ptr + strlen(av[i]) + 1) < av[0] + 4096)
            arg_ptr += strlen(av[i]) + 1;
          i++;
        }
      }
    }
    *ac = i;
    __real_fclose(infile);
  }
}


x86 assembly (clang, -O0):
<getProcCmdLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x18(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    $0x40,%esi
lea    0xe0d(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1030 <__real_fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1353 <getProcCmdLine+0x1b3>
mov    -0x78(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
jne    1341 <getProcCmdLine+0x1a1>
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x78(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   10c0 <__real_fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    133c <getProcCmdLine+0x19c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1337 <getProcCmdLine+0x197>
cmpl   $0x0,-0x14(%rbp)
je     12bf <getProcCmdLine+0x11f>
mov    -0x80(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%esi
mov    -0x80(%rbp),%rdx
lea    0xd59(%rip),%rdi
call   1060 <printf@plt>
mov    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
add    $0x1000,%rcx
cmp    %rcx,%rax
jae    1329 <getProcCmdLine+0x189>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x80(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1282 <getProcCmdLine+0xe2>
jmp    133c <getProcCmdLine+0x19c>
jmp    1341 <getProcCmdLine+0x1a1>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x78(%rbp),%rdi
call   1090 <__real_fclose@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProcCmdLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r12
mov    %rdi,%r14
movl   $0x0,(%rdi)
movq   $0x0,(%rsi)
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe2f(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
call   1070 <snprintf@plt>
lea    0xe27(%rip),%rsi
mov    %rbp,%rdi
call   1030 <__real_fopen@plt>
test   %rax,%rax
je     1211 <getProcCmdLine+0x71>
mov    %rax,%r15
mov    %rax,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1220 <getProcCmdLine+0x80>
mov    %ebx,(%r14)
mov    %r15,%rdi
call   1090 <__real_fclose@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1000,%edi
call   10b0 <malloc@plt>
mov    %rax,(%r12)
xor    %ebx,%ebx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1080 <memset@plt>
mov    (%r12),%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r15,%rcx
call   10c0 <__real_fread@plt>
test   %eax,%eax
jle    1206 <getProcCmdLine+0x66>
mov    (%r12),%r13
cmpb   $0x0,0x0(%r13)
je     1206 <getProcCmdLine+0x66>
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
add    %r13,%rax
add    $0x1,%rax
mov    (%r12),%rdi
lea    0x1000(%rdi),%rcx
cmp    %rcx,%rax
jae    1293 <getProcCmdLine+0xf3>
call   1050 <strlen@plt>
cltq
add    %rax,%r13
add    $0x1,%r13
cmpb   $0x0,0x0(%r13)
je     1306 <getProcCmdLine+0x166>
mov    $0x1,%ebx
mov    $0x1000,%ebp
jmp    12bf <getProcCmdLine+0x11f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmpb   $0x0,0x0(%r13)
je     1206 <getProcCmdLine+0x66>
mov    %r13,(%r12,%rbx,8)
lea    0xd49(%rip),%rdi
mov    %ebx,%esi
mov    %r13,%rdx
call   1060 <printf@plt>
mov    (%r12,%rbx,8),%rdi
call   1050 <strlen@plt>
cltq
add    %r13,%rax
add    $0x1,%rax
mov    (%r12),%rcx
add    %rbp,%rcx
cmp    %rcx,%rax
jae    12b0 <getProcCmdLine+0x110>
mov    (%r12,%rbx,8),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%r13
add    $0x1,%r13
jmp    12b0 <getProcCmdLine+0x110>
mov    $0x1,%ebx
jmp    1206 <getProcCmdLine+0x66>

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/%d/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%d: %s\0A\00"
define void @getProcCmdLine(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [64 x i8]
%10 = alloca i32*
%11 = alloca i8*
store i32* %0, i32** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %7
%12 = load i32*, i32** %3
store i32 0, i32* %12
%13 = load i8**, i8*** %4
store i8* null, i8** %13
%14 = call i32 (...) @getpid()
store i32 %14, i32* %6
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%16 = load i32, i32* %6
%17 = call i32 @snprintf(i8* %15, i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%19 = call i32* @__real_fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %99
22: ; preds = %2
%23 = load i32*, i32** %10
%24 = call i32 @feof(i32* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %94, label %26
26: ; preds = %22
%27 = call i8* @malloc(i32 4096)
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 0
store i8* %27, i8** %29
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @memset(i8* %32, i32 0, i32 4096)
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = load i32*, i32** %10
%38 = call i32 @__real_fread(i8* %36, i32 1, i32 4096, i32* %37)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %93
41: ; preds = %26
%42 = load i8**, i8*** %4
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
store i8* %44, i8** %11
br label %45
45: ; preds = %89, %41
%46 = load i8*, i8** %11
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %92
50: ; preds = %45
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i8*, i8** %11
%55 = load i8**, i8*** %4
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
store i8* %54, i8** %58
%59 = load i32, i32* %5
%60 = load i8*, i8** %11
%61 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %59, i8* %60)
br label %62
62: ; preds = %53, %50
%63 = load i8*, i8** %11
%64 = load i8**, i8*** %4
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @strlen(i8* %68)
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %63, i64 %70
%72 = getelementptr inbounds i8, i8* %71, i64 1
%73 = load i8**, i8*** %4
%74 = getelementptr inbounds i8*, i8** %73, i64 0
%75 = load i8*, i8** %74
%76 = getelementptr inbounds i8, i8* %75, i64 4096
%77 = icmp ult i8* %72, %76
br i1 %77, label %78, label %89
78: ; preds = %62
%79 = load i8**, i8*** %4
%80 = load i32, i32* %5
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8*, i8** %79, i64 %81
%83 = load i8*, i8** %82
%84 = call i32 @strlen(i8* %83)
%85 = add nsw i32 %84, 1
%86 = load i8*, i8** %11
%87 = sext i32 %85 to i64
%88 = getelementptr inbounds i8, i8* %86, i64 %87
store i8* %88, i8** %11
br label %89
89: ; preds = %78, %62
%90 = load i32, i32* %5
%91 = add nsw i32 %90, 1
store i32 %91, i32* %5
br label %45
92: ; preds = %45
br label %93
93: ; preds = %92, %26
br label %94
94: ; preds = %93, %22
%95 = load i32, i32* %5
%96 = load i32*, i32** %3
store i32 %95, i32* %96
%97 = load i32*, i32** %10
%98 = call i32 @__real_fclose(i32* %97)
br label %99
99: ; preds = %94, %2
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/%d/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%d: %s\0A\00"
define void @getProcCmdLine(i32* nocapture writeonly %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
store i32 0, i32* %0
store i8* null, i8** %1
%5 = tail call i32 (...) @getpid()
%6 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i32* @__real_fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %70, label %9
9: ; preds = %2
%10 = call i32 @feof(i32* %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %67
12: ; preds = %9
%13 = call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
store i8* %13, i8** %1
%14 = call i32 @memset(i8* %13, i32 0, i32 4096)
%15 = load i8*, i8** %1
%16 = call i32 @__real_fread(i8* %15, i32 1, i32 4096, i32* %7)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %67
18: ; preds = %12
%19 = load i8*, i8** %1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %67, label %22
22: ; preds = %18
%23 = call i32 @strlen(i8* %19)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8*, i8** %1
%28 = getelementptr inbounds i8, i8* %27, i64 4096
%29 = icmp ult i8* %26, %28
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = call i32 @strlen(i8* %27)
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %19, i64 %33
br label %35
35: ; preds = %30, %22
%36 = phi i8* [ %34, %30 ], [ %19, %22 ]
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %67, label %39
39: ; preds = %35, %60
%40 = phi i64 [ %62, %60 ], [ 1, %35 ]
%41 = phi i8* [ %61, %60 ], [ %36, %35 ]
%42 = getelementptr inbounds i8*, i8** %1, i64 %40
store i8* %41, i8** %42
%43 = trunc i64 %40 to i32
%44 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %43, i8* %41)
%45 = getelementptr inbounds i8*, i8** %1, i64 %40
%46 = load i8*, i8** %45
%47 = call i32 @strlen(i8* %46)
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %41, i64 1
%50 = getelementptr inbounds i8, i8* %49, i64 %48
%51 = load i8*, i8** %1
%52 = getelementptr inbounds i8, i8* %51, i64 4096
%53 = icmp ult i8* %50, %52
br i1 %53, label %54, label %60
54: ; preds = %39
%55 = load i8*, i8** %45
%56 = call i32 @strlen(i8* %55)
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %41, i64 %58
br label %60
60: ; preds = %54, %39
%61 = phi i8* [ %59, %54 ], [ %41, %39 ]
%62 = add nuw i64 %40, 1
%63 = load i8, i8* %61
%64 = icmp eq i8 %63, 0
br i1 %64, label %65, label %39
65: ; preds = %60
%66 = trunc i64 %62 to i32
br label %67
67: ; preds = %35, %65, %18, %12, %9
%68 = phi i32 [ 0, %9 ], [ 0, %12 ], [ 0, %18 ], [ 1, %35 ], [ %66, %65 ]
store i32 %68, i32* %0
%69 = call i32 @__real_fclose(i32* %7)
br label %70
70: ; preds = %67, %2
ret void
}