#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__ pid_t;

/* Variables and functions */
scalar_t__ atoi(char *);
scalar_t__ devspec_init(int *);
scalar_t__ get_current_record_pid(int, scalar_t__);
int getopt(int, char **, char *);
int /*<<< orphan*/ print_help(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int c;
  while ((c = getopt(argc, argv, "h")) != -1) {
    switch (c) {
    case 'h':
    default:
      print_help(argv[0]);
      return -1;
    }
  }
  if (argc != 2) {
    printf("ERROR\n");
    printf("Wrong number of arguments\n");
    print_help(argv[0]);
    return -1;
  }
  pid_t pid = atoi(argv[1]);
  int fd;
  if (devspec_init(&fd)) {
    printf("ERROR\n");
    return -1;
  }
  pid_t record_pid = get_current_record_pid(fd, pid);
  if (record_pid < 0) {
    printf("ERROR\n");
    printf("get_current_record_pid failed\n");
    return -1;
  }
  printf("%i\n", record_pid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11c3 <main+0x63>
mov    -0x14(%rbp),%eax
sub    $0x68,%eax
jne    11ab <main+0x4b>
jmp    11a6 <main+0x46>
jmp    11ab <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <print_help@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <main+0x13b>
cmpl   $0x2,-0x8(%rbp)
je     1201 <main+0xa1>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <print_help@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <main+0x13b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <devspec_init@plt>
cmp    $0x0,%rax
je     123f <main+0xdf>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <main+0x13b>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1040 <get_current_record_pid@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1282 <main+0x122>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <main+0x13b>
mov    -0x30(%rbp),%rsi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe81(%rip),%rdx
call   1070 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11cf <main+0x5f>
cmp    $0x2,%ebp
jne    11b7 <main+0x47>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
call   1040 <devspec_init@plt>
test   %rax,%rax
je     11e5 <main+0x75>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
jmp    11d7 <main+0x67>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
call   1090 <print_help@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1050 <get_current_record_pid@plt>
test   %rax,%rax
js     120b <main+0x9b>
lea    0xe05(%rip),%rdi
xor    %ebx,%ebx
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11dc <main+0x6c>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
lea    0xde8(%rip),%rdi
jmp    11b0 <main+0x40>

LLVM IR (-O0):
@.str = [2 x i8] c"h\00"
@.str.1 = [7 x i8] c"ERROR\0A\00"
@.str.2 = [27 x i8] c"Wrong number of arguments\0A\00"
@.str.3 = [31 x i8] c"get_current_record_pid failed\0A\00"
@.str.4 = [4 x i8] c"%i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %18 [
i32 104, label %17
]
17: ; preds = %15
br label %18
18: ; preds = %15, %17
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @print_help(i8* %21)
store i32 -1, i32* %3
br label %54
23: ; preds = %10
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 2
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @print_help(i8* %31)
store i32 -1, i32* %3
br label %54
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @atoi(i8* %36)
store i64 %37, i64* %7
%38 = call i64 @devspec_init(i32* %8)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
42: ; preds = %33
%43 = load i32, i32* %8
%44 = load i64, i64* %7
%45 = call i64 @get_current_record_pid(i32 %43, i64 %44)
store i64 %45, i64* %9
%46 = load i64, i64* %9
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
51: ; preds = %42
%52 = load i64, i64* %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %51, %48, %40, %26, %18
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c"h\00"
@.str.4 = [4 x i8] c"%i\0A\00"
@str.5 = [30 x i8] c"get_current_record_pid failed\00"
@str.7 = [6 x i8] c"ERROR\00"
@str.8 = [26 x i8] c"Wrong number of arguments\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @print_help(i8* %7)
br label %36
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %16, label %11
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
%14 = load i8*, i8** %1
%15 = tail call i32 @print_help(i8* %14)
br label %36
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @atoi(i8* %18)
%20 = bitcast i32* %3 to i8*
%21 = call i64 @devspec_init(i32* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %16
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0))
br label %34
25: ; preds = %16
%26 = load i32, i32* %3
%27 = call i64 @get_current_record_pid(i32 %26, i64 %19)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0))
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
br label %34
32: ; preds = %25
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64 %27)
br label %34
34: ; preds = %29, %32, %23
%35 = phi i32 [ -1, %23 ], [ -1, %29 ], [ 0, %32 ]
br label %36
36: ; preds = %34, %11, %6
%37 = phi i32 [ -1, %6 ], [ -1, %11 ], [ %35, %34 ]
ret i32 %37
}