#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*/ cmdline_filename;
typedef int /*<<< orphan*/ cbuf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char *);
char *get_cmdline(int pid) {
  int fd, rc, i;
  char cmdline_filename[32];
  static char cbuf[8192];
  snprintf(cmdline_filename, sizeof(cmdline_filename), "/proc/%u/cmdline", pid);
  fd = open(cmdline_filename, O_RDONLY);
  if (fd == -1) {
    return (NULL);
  }
  rc = read(fd, cbuf, sizeof(cbuf));
  if (rc == -1) {
    close(fd);
    return (NULL);
  }
  if (rc - strlen(cbuf) > 1) {
    for (i = 0; i < rc; i++)
      if (cbuf[i] == '\0')
        cbuf[i] = ' ';
    cbuf[rc] = '\0';
  }
  close(fd);
  return cbuf;
}


x86 assembly (clang, -O0):
<get_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x20,%esi
lea    0xe92(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    119f <get_cmdline+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    1266 <get_cmdline+0x116>
mov    -0x10(%rbp),%edi
lea    0x2eb7(%rip),%rsi
mov    $0x2000,%edx
call   1060 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d5 <get_cmdline+0x85>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1266 <get_cmdline+0x116>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    0x2e7e(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
sub    %ecx,%eax
cmp    $0x1,%eax
jle    1253 <get_cmdline+0x103>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1244 <get_cmdline+0xf4>
movslq -0x18(%rbp),%rcx
lea    0x2e4b(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1231 <get_cmdline+0xe1>
movslq -0x18(%rbp),%rcx
lea    0x2e33(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
jmp    1236 <get_cmdline+0xe6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fe <get_cmdline+0xae>
movslq -0x14(%rbp),%rcx
lea    0x2e11(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    0x2dfe(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cmdline>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ecx
lea    0xe9f(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <snprintf@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d6 <get_cmdline+0x86>
mov    %eax,%ebx
lea    0x2ed0(%rip),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     11dd <get_cmdline+0x8d>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r14d,%ecx
sub    %eax,%ecx
cmp    $0x2,%ecx
jl     13a9 <get_cmdline+0x259>
test   %r14d,%r14d
jle    139b <get_cmdline+0x24b>
mov    %r14d,%eax
cmp    $0x10,%r14d
jae    11e4 <get_cmdline+0x94>
xor    %ecx,%ecx
jmp    13bc <get_cmdline+0x26c>
xor    %ebp,%ebp
jmp    13b0 <get_cmdline+0x260>
xor    %ebp,%ebp
jmp    13a9 <get_cmdline+0x259>
mov    %eax,%ecx
and    $0xfffffff0,%ecx
xor    %edx,%edx
lea    0x2e6e(%rip),%rsi
pxor   %xmm0,%xmm0
jmp    120d <get_cmdline+0xbd>
nopl   0x0(%rax,%rax,1)
add    $0x10,%rdx
cmp    %rdx,%rcx
je     1396 <get_cmdline+0x246>
movq   (%rdx,%rsi,1),%xmm2
movdqa %xmm2,%xmm1
pcmpeqb %xmm0,%xmm1
movd   %xmm1,%edi
test   $0x1,%dil
je     1228 <get_cmdline+0xd8>
movb   $0x20,(%rdx,%rsi,1)
movdqa %xmm1,%xmm3
pslld  $0x8,%xmm3
movd   %xmm3,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     1243 <get_cmdline+0xf3>
movb   $0x20,0x1(%rdx,%rsi,1)
pshuflw $0x55,%xmm2,%xmm3
pcmpeqb %xmm0,%xmm3
pextrw $0x2,%xmm3,%edi
test   $0x1,%dil
je     125c <get_cmdline+0x10c>
movb   $0x20,0x2(%rdx,%rsi,1)
movdqa %xmm1,%xmm3
psllq  $0x18,%xmm3
pextrw $0x3,%xmm3,%edi
test   $0x1,%dil
je     1275 <get_cmdline+0x125>
movb   $0x20,0x3(%rdx,%rsi,1)
pshufd $0x55,%xmm2,%xmm2
pcmpeqb %xmm0,%xmm2
pextrw $0x4,%xmm2,%edi
test   $0x1,%dil
je     128e <get_cmdline+0x13e>
movb   $0x20,0x4(%rdx,%rsi,1)
movdqa %xmm1,%xmm2
pslldq $0x5,%xmm2
pextrw $0x5,%xmm2,%edi
test   $0x1,%dil
je     12a7 <get_cmdline+0x157>
movb   $0x20,0x5(%rdx,%rsi,1)
pextrw $0x3,%xmm1,%edi
test   $0x1,%dil
je     12b7 <get_cmdline+0x167>
movb   $0x20,0x6(%rdx,%rsi,1)
pslldq $0x7,%xmm1
pextrw $0x7,%xmm1,%edi
test   $0x1,%dil
je     12cc <get_cmdline+0x17c>
movb   $0x20,0x7(%rdx,%rsi,1)
movq   0x8(%rdx,%rsi,1),%xmm2
movdqa %xmm2,%xmm1
pcmpeqb %xmm0,%xmm1
movd   %xmm1,%edi
test   $0x1,%dil
je     12e9 <get_cmdline+0x199>
movb   $0x20,0x8(%rdx,%rsi,1)
movdqa %xmm1,%xmm3
pslld  $0x8,%xmm3
movd   %xmm3,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     1304 <get_cmdline+0x1b4>
movb   $0x20,0x9(%rdx,%rsi,1)
pshuflw $0x55,%xmm2,%xmm3
pcmpeqb %xmm0,%xmm3
pextrw $0x2,%xmm3,%edi
test   $0x1,%dil
je     131d <get_cmdline+0x1cd>
movb   $0x20,0xa(%rdx,%rsi,1)
movdqa %xmm1,%xmm3
psllq  $0x18,%xmm3
pextrw $0x3,%xmm3,%edi
test   $0x1,%dil
je     1336 <get_cmdline+0x1e6>
movb   $0x20,0xb(%rdx,%rsi,1)
pshufd $0x55,%xmm2,%xmm2
pcmpeqb %xmm0,%xmm2
pextrw $0x4,%xmm2,%edi
test   $0x1,%dil
je     134f <get_cmdline+0x1ff>
movb   $0x20,0xc(%rdx,%rsi,1)
movdqa %xmm1,%xmm2
pslldq $0x5,%xmm2
pextrw $0x5,%xmm2,%edi
test   $0x1,%dil
je     1368 <get_cmdline+0x218>
movb   $0x20,0xd(%rdx,%rsi,1)
pextrw $0x3,%xmm1,%edi
test   $0x1,%dil
je     1378 <get_cmdline+0x228>
movb   $0x20,0xe(%rdx,%rsi,1)
pslldq $0x7,%xmm1
pextrw $0x7,%xmm1,%edi
test   $0x1,%dil
je     1200 <get_cmdline+0xb0>
movb   $0x20,0xf(%rdx,%rsi,1)
jmp    1200 <get_cmdline+0xb0>
cmp    %rax,%rcx
jne    13bc <get_cmdline+0x26c>
movslq %r14d,%rax
lea    0x2cbb(%rip),%rbp
movb   $0x0,(%rax,%rbp,1)
mov    %ebx,%edi
call   1050 <close@plt>
mov    %rbp,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x2c9d(%rip),%rdx
jmp    13d9 <get_cmdline+0x289>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rcx
cmp    %rcx,%rax
je     139b <get_cmdline+0x24b>
cmpb   $0x0,(%rcx,%rdx,1)
jne    13d0 <get_cmdline+0x280>
movb   $0x20,(%rcx,%rdx,1)
jmp    13d0 <get_cmdline+0x280>

LLVM IR (-O0):
@get_cmdline.cbuf = internal global [8192 x i8] zeroinitializer
@.str = [17 x i8] c"/proc/%u/cmdline\00"
@O_RDONLY = global i32 0
define i8* @get_cmdline(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [32 x i8]
store i32 %0, i32* %3
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %3
%10 = call i32 @snprintf(i8* %8, i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %1
store i8* null, i8** %2
br label %57
17: ; preds = %1
%18 = load i32, i32* %4
%19 = call i32 @read(i32 %18, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0), i32 8192)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
store i8* null, i8** %2
br label %57
25: ; preds = %17
%26 = load i32, i32* %5
%27 = call i32 @strlen(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0))
%28 = sub nsw i32 %26, %27
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %54
30: ; preds = %25
store i32 0, i32* %6
br label %31
31: ; preds = %47, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %44
store i8 32, i8* %45
br label %46
46: ; preds = %42, %35
br label %47
47: ; preds = %46
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %31
50: ; preds = %31
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %50, %25
%55 = load i32, i32* %4
%56 = call i32 @close(i32 %55)
store i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0), i8** %2
br label %57
57: ; preds = %54, %22, %16
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@get_cmdline.cbuf = internal global [8192 x i8] zeroinitializer
@.str = [17 x i8] c"/proc/%u/cmdline\00"
@O_RDONLY = global i32 0
define i8* @get_cmdline(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* %3, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %132, label %8
8: ; preds = %1
%9 = call i32 @read(i32 %6, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0), i32 8192)
%10 = icmp eq i32 %9, -1
br i1 %10, label %129, label %11
11: ; preds = %8
%12 = call i32 @strlen(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0))
%13 = sub nsw i32 %9, %12
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %129
15: ; preds = %11
%16 = icmp sgt i32 %9, 0
br i1 %16, label %17, label %126
17: ; preds = %15
%18 = zext i32 %9 to i64
%19 = icmp ult i32 %9, 16
br i1 %19, label %115, label %20
20: ; preds = %17
%21 = and i64 %18, 4294967280
br label %22
22: ; preds = %110, %20
%23 = phi i64 [ 0, %20 ], [ %111, %110 ]
%24 = or i64 %23, 8
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %23
%26 = bitcast i8* %25 to <8 x i8>*
%27 = load <8 x i8>, <8 x i8>* %26
%28 = getelementptr inbounds i8, i8* %25, i64 8
%29 = bitcast i8* %28 to <8 x i8>*
%30 = load <8 x i8>, <8 x i8>* %29
%31 = icmp eq <8 x i8> %27, zeroinitializer
%32 = icmp eq <8 x i8> %30, zeroinitializer
%33 = extractelement <8 x i1> %31, i64 0
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %23
store i8 32, i8* %35
br label %36
36: ; preds = %34, %22
%37 = extractelement <8 x i1> %31, i64 1
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = or i64 %23, 1
%40 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %39
store i8 32, i8* %40
br label %41
41: ; preds = %38, %36
%42 = extractelement <8 x i1> %31, i64 2
br i1 %42, label %43, label %46
43: ; preds = %41
%44 = or i64 %23, 2
%45 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %44
store i8 32, i8* %45
br label %46
46: ; preds = %43, %41
%47 = extractelement <8 x i1> %31, i64 3
br i1 %47, label %48, label %51
48: ; preds = %46
%49 = or i64 %23, 3
%50 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %49
store i8 32, i8* %50
br label %51
51: ; preds = %48, %46
%52 = extractelement <8 x i1> %31, i64 4
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = or i64 %23, 4
%55 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %54
store i8 32, i8* %55
br label %56
56: ; preds = %53, %51
%57 = extractelement <8 x i1> %31, i64 5
br i1 %57, label %58, label %61
58: ; preds = %56
%59 = or i64 %23, 5
%60 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %59
store i8 32, i8* %60
br label %61
61: ; preds = %58, %56
%62 = extractelement <8 x i1> %31, i64 6
br i1 %62, label %63, label %66
63: ; preds = %61
%64 = or i64 %23, 6
%65 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %64
store i8 32, i8* %65
br label %66
66: ; preds = %63, %61
%67 = extractelement <8 x i1> %31, i64 7
br i1 %67, label %68, label %71
68: ; preds = %66
%69 = or i64 %23, 7
%70 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %69
store i8 32, i8* %70
br label %71
71: ; preds = %68, %66
%72 = extractelement <8 x i1> %32, i64 0
br i1 %72, label %73, label %75
73: ; preds = %71
%74 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %24
store i8 32, i8* %74
br label %75
75: ; preds = %73, %71
%76 = extractelement <8 x i1> %32, i64 1
br i1 %76, label %77, label %80
77: ; preds = %75
%78 = or i64 %23, 9
%79 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %78
store i8 32, i8* %79
br label %80
80: ; preds = %77, %75
%81 = extractelement <8 x i1> %32, i64 2
br i1 %81, label %82, label %85
82: ; preds = %80
%83 = or i64 %23, 10
%84 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %83
store i8 32, i8* %84
br label %85
85: ; preds = %82, %80
%86 = extractelement <8 x i1> %32, i64 3
br i1 %86, label %87, label %90
87: ; preds = %85
%88 = or i64 %23, 11
%89 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %88
store i8 32, i8* %89
br label %90
90: ; preds = %87, %85
%91 = extractelement <8 x i1> %32, i64 4
br i1 %91, label %92, label %95
92: ; preds = %90
%93 = or i64 %23, 12
%94 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %93
store i8 32, i8* %94
br label %95
95: ; preds = %92, %90
%96 = extractelement <8 x i1> %32, i64 5
br i1 %96, label %97, label %100
97: ; preds = %95
%98 = or i64 %23, 13
%99 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %98
store i8 32, i8* %99
br label %100
100: ; preds = %97, %95
%101 = extractelement <8 x i1> %32, i64 6
br i1 %101, label %102, label %105
102: ; preds = %100
%103 = or i64 %23, 14
%104 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %103
store i8 32, i8* %104
br label %105
105: ; preds = %102, %100
%106 = extractelement <8 x i1> %32, i64 7
br i1 %106, label %107, label %110
107: ; preds = %105
%108 = or i64 %23, 15
%109 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %108
store i8 32, i8* %109
br label %110
110: ; preds = %107, %105
%111 = add nuw i64 %23, 16
%112 = icmp eq i64 %111, %21
br i1 %112, label %113, label %22
113: ; preds = %110
%114 = icmp eq i64 %21, %18
br i1 %114, label %126, label %115
115: ; preds = %17, %113
%116 = phi i64 [ 0, %17 ], [ %21, %113 ]
br label %117
117: ; preds = %115, %123
%118 = phi i64 [ %124, %123 ], [ %116, %115 ]
%119 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %118
%120 = load i8, i8* %119
%121 = icmp eq i8 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %117
store i8 32, i8* %119
br label %123
123: ; preds = %117, %122
%124 = add nuw nsw i64 %118, 1
%125 = icmp eq i64 %124, %18
br i1 %125, label %126, label %117
126: ; preds = %123, %113, %15
%127 = sext i32 %9 to i64
%128 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 %127
store i8 0, i8* %128
br label %129
129: ; preds = %11, %126, %8
%130 = phi i8* [ null, %8 ], [ getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0), %126 ], [ getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_cmdline.cbuf, i64 0, i64 0), %11 ]
%131 = call i32 @close(i32 %6)
br label %132
132: ; preds = %129, %1
%133 = phi i8* [ null, %1 ], [ %130, %129 ]
ret i8* %133
}