#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ SYS_read;
scalar_t__ errno;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, long, long, long, long);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, scalar_t__);
scalar_t__ sys_read(int, char *, int);
int main(void) {
  char buf1[64];
  char buf2[64];
  int fd;
  ssize_t rv;
  fd = open("/proc/self/syscall", O_RDONLY);
  if (fd == -1) {
    if (errno == ENOENT)
      return 4;
    return 1;
  }
  snprintf(buf1, sizeof(buf1), "%ld 0x%lx 0x%lx 0x%lx", (long)SYS_read,
           (long)fd, (long)buf2, (long)sizeof(buf2));
  memset(buf2, 0, sizeof(buf2));
  rv = sys_read(fd, buf2, sizeof(buf2));
  if (rv < 0)
    return 1;
  if (rv < strlen(buf1))
    return 1;
  if (strncmp(buf1, buf2, strlen(buf1)) != 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0xffffffff,-0x94(%rbp)
jne    11cc <main+0x6c>
mov    0x2e2f(%rip),%rax
mov    (%rax),%rax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <main+0x60>
movl   $0x4,-0x4(%rbp)
jmp    12d7 <main+0x177>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <main+0x177>
lea    -0x50(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%rcx
movslq -0x94(%rbp),%r8
lea    -0x90(%rbp),%r9
mov    $0x40,%esi
lea    0xe1f(%rip),%rdx
movq   $0x40,(%rsp)
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x40,%edx
call   1080 <sys_read@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jge    124c <main+0xec>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <main+0x177>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xa8(%rbp),%rax
cmp    %rcx,%rax
jge    1282 <main+0x122>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <main+0x177>
lea    -0x50(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xb8(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12d0 <main+0x170>
movl   $0x1,-0x4(%rbp)
jmp    12d7 <main+0x177>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1213 <main+0xb3>
mov    %eax,%ebx
mov    0x2e4f(%rip),%rax
mov    (%rax),%rcx
movslq %ebx,%r8
movq   $0x40,(%rsp)
lea    0xe6d(%rip),%rdx
lea    0x10(%rsp),%rdi
lea    0x50(%rsp),%r14
mov    $0x40,%esi
mov    %r14,%r9
call   1050 <snprintf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1080 <sys_read@plt>
mov    $0x1,%ebx
test   %rax,%rax
js     1232 <main+0xd2>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
cmp    %rax,%r14
jl     1232 <main+0xd2>
lea    0x10(%rsp),%rdi
lea    0x50(%rsp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
jmp    1232 <main+0xd2>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    0x2d9c(%rip),%rcx
xor    %edx,%edx
cmp    (%rcx),%rax
sete   %dl
lea    (%rdx,%rdx,2),%ebx
add    $0x1,%ebx
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/proc/self/syscall\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [22 x i8] c"%ld 0x%lx 0x%lx 0x%lx\00"
@SYS_read = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 4, i32* %1
br label %47
15: ; preds = %10
store i32 1, i32* %1
br label %47
16: ; preds = %0
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%18 = load i64, i64* @SYS_read
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%22 = ptrtoint i8* %21 to i64
%23 = call i32 @snprintf(i8* %17, i32 64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %18, i64 %20, i64 %22, i64 64)
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 64)
%26 = load i32, i32* %4
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%28 = call i64 @sys_read(i32 %26, i8* %27, i32 64)
store i64 %28, i64* %5
%29 = load i64, i64* %5
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %16
store i32 1, i32* %1
br label %47
32: ; preds = %16
%33 = load i64, i64* %5
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%35 = call i64 @strlen(i8* %34)
%36 = icmp slt i64 %33, %35
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %1
br label %47
38: ; preds = %32
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%42 = call i64 @strlen(i8* %41)
%43 = call i64 @strncmp(i8* %39, i8* %40, i64 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %38
store i32 1, i32* %1
br label %47
46: ; preds = %38
store i32 0, i32* %1
br label %47
47: ; preds = %46, %45, %37, %31, %15, %14
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [19 x i8] c"/proc/self/syscall\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.1 = [22 x i8] c"%ld 0x%lx 0x%lx 0x%lx\00"
@SYS_read = global i64 0
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
%12 = select i1 %11, i32 4, i32 1
br label %28
13: ; preds = %0
%14 = load i64, i64* @SYS_read
%15 = sext i32 %6 to i64
%16 = ptrtoint [64 x i8]* %2 to i64
%17 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i64 %14, i64 %15, i64 %16, i64 64)
%18 = call i32 @memset(i8* %4, i32 0, i32 64)
%19 = call i64 @sys_read(i32 %6, i8* %4, i32 64)
%20 = icmp slt i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %13
%22 = call i64 @strlen(i8* %3)
%23 = icmp slt i64 %19, %22
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i64 @strncmp(i8* %3, i8* %4, i64 %22)
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %24, %21, %13, %8
%29 = phi i32 [ %12, %8 ], [ 1, %13 ], [ 1, %21 ], [ %27, %24 ]
ret i32 %29
}