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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ mystrstr(char *, char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int getNoKill(void) {
  int fd;
  int len;
  char buf[1024];
  if ((fd = open("/proc/cmdline", O_RDONLY, 0)) > 0) {
    len = read(fd, buf, sizeof(buf) - 1);
    close(fd);
    if (len > 0 && mystrstr(buf, "nokill"))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getNoKill>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11c5 <getNoKill+0x85>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11c0 <getNoKill+0x80>
lea    -0x410(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1030 <mystrstr@plt>
cmp    $0x0,%rax
je     11c0 <getNoKill+0x80>
movl   $0x1,-0x4(%rbp)
jmp    11cc <getNoKill+0x8c>
jmp    11c5 <getNoKill+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNoKill>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
xor    %edx,%edx
call   1060 <open@plt>
test   %eax,%eax
jle    119e <getNoKill+0x5e>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x3ff,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
test   %ebp,%ebp
jle    119e <getNoKill+0x5e>
lea    0xe85(%rip),%rsi
mov    %rsp,%rdi
call   1030 <mystrstr@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11a0 <getNoKill+0x60>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cmdline\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"nokill\00"
define i32 @getNoKill() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %5, i32 0)
store i32 %6, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = load i32, i32* %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 1023)
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %8
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = call i64 @mystrstr(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %1
br label %23
21: ; preds = %16, %8
br label %22
22: ; preds = %21, %0
store i32 0, i32* %1
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cmdline\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"nokill\00"
define i32 @getNoKill() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = call i32 @read(i32 %4, i8* %2, i32 1023)
%8 = tail call i32 @close(i32 %4)
%9 = icmp sgt i32 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = call i64 @mystrstr(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %6, %10, %0
br label %14
14: ; preds = %10, %13
%15 = phi i32 [ 0, %13 ], [ 1, %10 ]
ret i32 %15
}