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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int atoi(char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int load_pid_file(char *path) {
  char pid_str[11];
  int fd;
  assert(path != NULL);
  fd = open(path, O_RDONLY);
  if (fd == -1) {
    return -1;
  }
  if (read(fd, pid_str, 11) == -1) {
    return -1;
  }
  return atoi(pid_str);
}


x86 assembly (clang, -O0):
<load_pid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1189 <load_pid_file+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <load_pid_file+0x7b>
mov    -0x20(%rbp),%edi
lea    -0x1b(%rbp),%rsi
mov    $0xb,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
jne    11af <load_pid_file+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <load_pid_file+0x7b>
lea    -0x1b(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_pid_file>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <open@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1193 <load_pid_file+0x53>
lea    0x5(%rsp),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     1193 <load_pid_file+0x53>
lea    0x5(%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @load_pid_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [11 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %25
16: ; preds = %1
%17 = load i32, i32* %5
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 11)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %2
br label %25
22: ; preds = %16
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %2
br label %25
25: ; preds = %22, %21, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @load_pid_file(i8* %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = call i32 @read(i32 %8, i8* %3, i32 11)
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @atoi(i8* %3)
br label %15
15: ; preds = %10, %1, %13
%16 = phi i32 [ %14, %13 ], [ -1, %1 ], [ -1, %10 ]
ret i32 %16
}