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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int get_ckpt_status(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_help(char *);
int main(int argc, char *argv[]) {
  int fd, rc;
  pid_t pid;
  if (argc != 2)
    print_help(argv[0]);
  pid = atoi(argv[1]);
  fd = open("/dev/spec0", O_RDWR);
  if (fd < 0) {
    perror("open /dev/spec0");
    return fd;
  }
  rc = get_ckpt_status(fd, pid);
  if (rc != 1) {
    return -1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118c <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <print_help@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <main+0x75>
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1208 <main+0xa8>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <get_ckpt_status@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     11f9 <main+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <main+0xa8>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1173 <main+0x13>
mov    (%rbx),%rdi
call   1080 <print_help@plt>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe77(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11be <main+0x5e>
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <get_ckpt_status@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x1,%ecx
jne    11b7 <main+0x57>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%eax
jmp    11b7 <main+0x57>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/spec0\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open /dev/spec0\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @print_help(i8* %14)
br label %16
16: ; preds = %11, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %6
store i32 %27, i32* %3
br label %38
28: ; preds = %16
%29 = load i32, i32* %6
%30 = load i32, i32* %8
%31 = call i32 @get_ckpt_status(i32 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 -1, i32* %3
br label %38
35: ; preds = %28
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %38
38: ; preds = %35, %34, %25
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/spec0\00"
@O_RDWR = global i32 0
@.str.1 = [16 x i8] c"open /dev/spec0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @print_help(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %21
16: ; preds = %7
%17 = tail call i32 @get_ckpt_status(i32 %12, i32 %10)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @close(i32 %12)
br label %21
21: ; preds = %16, %19, %14
%22 = phi i32 [ %12, %14 ], [ 0, %19 ], [ -1, %16 ]
ret i32 %22
}