#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int);
int main() {
  char buf[32];
  FILE *fptr;
  int result = 1;
  int c;
  sprintf(buf, "/proc/%d/cmdline", getpid());
  fptr = fopen(buf, "r");
  if (fptr != 0) {
    while ((c = fgetc(fptr)) != EOF) {
      result = c;
    }
    fclose(fptr);
  }
  if (result != 0) {
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe7e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11da <main+0x8a>
jmp    11ab <main+0x5b>
mov    -0x38(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x40(%rbp)
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
je     11d1 <main+0x81>
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11ab <main+0x5b>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x3c(%rbp)
je     11eb <main+0x9b>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9a(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1070 <sprintf@plt>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b9 <main+0x69>
mov    %rax,%rbx
mov    $0x1,%eax
mov    0x2e52(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
jne    11a0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11be <main+0x6e>
mov    $0x1,%ebp
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/%d/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %4
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%7 = call i32 (...) @getpid()
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %24
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %3
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %5
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = load i32, i32* %5
store i32 %20, i32* %4
br label %14
21: ; preds = %14
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
br label %24
24: ; preds = %21, %0
%25 = load i32, i32* %4
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 1, i32* %4
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/%d/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getpid()
%4 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %0, %7
%8 = phi i32 [ %9, %7 ], [ 1, %0 ]
%9 = tail call i32 @fgetc(i32* %5)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %5)
br label %14
14: ; preds = %12, %0
%15 = phi i32 [ %8, %12 ], [ 1, %0 ]
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i32
ret i32 %17
}