#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ strtok(char *, char *);
int main() {
  FILE *fp = NULL;
  fp = fopen("/proc/cmdline", "r");
  if (NULL == fp) {
    perror("Fopen failed ");
    return -1;
    ;
  } else {
    char *buffer = NULL;
    char *pbuffer = NULL;
    size_t ret = 0;
    buffer = malloc(128 * sizeof(char));
    pbuffer = buffer;
    if (NULL == buffer) {
      perror("Malloc failed :");
      if (0 != fclose(fp)) {
        perror("File closing failed\n");
        return -1;
        ;
      }
      return -2;
    }
    ret = fread(buffer, 1, 128, fp);
    buffer = (char *)strtok(buffer, " ");
    while (NULL != buffer) {
      if (0 == strncmp(buffer, "root", sizeof("root") - 1)) {
        buffer = (char *)strtok(buffer, "=");
        buffer = (char *)strtok(NULL, " ");
        break;
      }
      buffer = (char *)strtok(NULL, " ");
    }
    if (NULL != buffer) {
      printf("%s : %s\n", "root", buffer);
    } else {
      printf("Variable %s is not found\n", "root");
    }
    free(pbuffer);
    if (0 != fclose(fp)) {
      perror("File closing failed\n");
      return -1;
      ;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe52(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11e2 <main+0x52>
lea    0xe3f(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <main+0x1fa>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1263 <main+0xd3>
lea    0xdfb(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1257 <main+0xc7>
lea    0xde8(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <main+0x1fa>
movl   $0xfffffffe,-0x4(%rbp)
jmp    138a <main+0x1fa>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1050 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd93(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1307 <main+0x177>
mov    -0x18(%rbp),%rdi
lea    0xd9a(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12ee <main+0x15e>
mov    -0x18(%rbp),%rdi
lea    0xd7c(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd3c(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1307 <main+0x177>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd23(%rip),%rsi
call   10b0 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1292 <main+0x102>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1331 <main+0x1a1>
mov    -0x18(%rbp),%rdx
lea    0xd2c(%rip),%rdi
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1346 <main+0x1b6>
lea    0xd1b(%rip),%rdi
lea    0xd04(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     137e <main+0x1ee>
lea    0xcc1(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <main+0x1fa>
jmp    1383 <main+0x1f3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe60(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ae <main+0x11e>
mov    %rax,%r14
mov    $0x80,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     12b7 <main+0x127>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
lea    0xe32(%rip),%rsi
mov    %r15,%rdi
call   10b0 <strtok@plt>
test   %rax,%rax
je     1275 <main+0xe5>
mov    %rax,%rbx
lea    0xe42(%rip),%r12
lea    0xe14(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1239 <main+0xa9>
xor    %edi,%edi
mov    %r13,%rsi
call   10b0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <main+0x80>
jmp    1275 <main+0xe5>
lea    0xe08(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strtok@plt>
lea    0xdcd(%rip),%rsi
xor    %edi,%edi
call   10b0 <strtok@plt>
test   %rax,%rax
je     1275 <main+0xe5>
lea    0xde8(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    128a <main+0xfa>
lea    0xdd7(%rip),%rdi
lea    0xdc0(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    12d8 <main+0x148>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd5b(%rip),%rdi
jmp    12df <main+0x14f>
lea    0xd60(%rip),%rdi
call   10a0 <perror@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
je     12a4 <main+0x114>
lea    0xd4f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
jmp    12a4 <main+0x114>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"Fopen failed \00"
@.str.3 = [16 x i8] c"Malloc failed :\00"
@.str.4 = [21 x i8] c"File closing failed\0A\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [5 x i8] c"root\00"
@.str.7 = [2 x i8] c"=\00"
@.str.8 = [9 x i8] c"%s : %s\0A\00"
@.str.9 = [26 x i8] c"Variable %s is not found\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
store i32* null, i32** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* null, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %65
11: ; preds = %0
store i8* null, i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
%12 = call i8* @malloc(i32 128)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
store i8* %13, i8** %4
%14 = load i8*, i8** %3
%15 = icmp eq i8* null, %14
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32*, i32** %2
%19 = call i64 @fclose(i32* %18)
%20 = icmp ne i64 0, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %65
23: ; preds = %16
store i32 -2, i32* %1
br label %65
24: ; preds = %11
%25 = load i8*, i8** %3
%26 = load i32*, i32** %2
%27 = call i64 @fread(i8* %25, i32 1, i32 128, i32* %26)
store i64 %27, i64* %5
%28 = load i8*, i8** %3
%29 = call i64 @strtok(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %3
br label %31
31: ; preds = %44, %24
%32 = load i8*, i8** %3
%33 = icmp ne i8* null, %32
br i1 %33, label %34, label %47
34: ; preds = %31
%35 = load i8*, i8** %3
%36 = call i64 @strncmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%37 = icmp eq i64 0, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i8*, i8** %3
%40 = call i64 @strtok(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %3
%42 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %3
br label %47
44: ; preds = %34
%45 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %3
br label %31
47: ; preds = %38, %31
%48 = load i8*, i8** %3
%49 = icmp ne i8* null, %48
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %51)
br label %55
53: ; preds = %47
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
%56 = load i8*, i8** %4
%57 = call i32 @free(i8* %56)
%58 = load i32*, i32** %2
%59 = call i64 @fclose(i32* %58)
%60 = icmp ne i64 0, %59
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %65
63: ; preds = %55
br label %64
64: ; preds = %63
store i32 0, i32* %1
br label %65
65: ; preds = %64, %61, %23, %21, %9
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"Fopen failed \00"
@.str.3 = [16 x i8] c"Malloc failed :\00"
@.str.4 = [21 x i8] c"File closing failed\0A\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [5 x i8] c"root\00"
@.str.7 = [2 x i8] c"=\00"
@.str.8 = [9 x i8] c"%s : %s\0A\00"
@.str.9 = [26 x i8] c"Variable %s is not found\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %36, label %3
3: ; preds = %0
%4 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i64 @fclose(i32* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %39, label %36
10: ; preds = %3
%11 = tail call i64 @fread(i8* %4, i32 1, i32 128, i32* %1)
%12 = tail call i64 @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %10, %19
%15 = phi i64 [ %20, %19 ], [ %12, %10 ]
%16 = inttoptr i64 %15 to i8*
%17 = tail call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = tail call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %30, label %14
22: ; preds = %14
%23 = inttoptr i64 %15 to i8*
%24 = tail call i64 @strtok(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%25 = tail call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = inttoptr i64 %25 to i8*
%29 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %28)
br label %32
30: ; preds = %19, %10, %22
%31 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = tail call i32 @free(i8* %4)
%34 = tail call i64 @fclose(i32* %1)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32, %6, %0
%37 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), %32 ]
%38 = tail call i32 @perror(i8* %37)
br label %39
39: ; preds = %36, %6, %32
%40 = phi i32 [ 0, %32 ], [ -2, %6 ], [ -1, %36 ]
ret i32 %40
}