#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 */
struct TalpaPacket_VettingDetails {
  int dummy;
};

/* Variables and functions */
scalar_t__ ETIME;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
unsigned int atoi(char *);
scalar_t__ errno;
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ vc_exit(int);
struct TalpaPacket_VettingDetails *vc_get(int);
int vc_init(unsigned int, unsigned int const);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  unsigned int group;
  const unsigned int tout = 2;
  char file[100];
  int talpa;
  int rc;
  struct TalpaPacket_VettingDetails *details;
  int status;
  if (argc > 1) {
    group = atoi(argv[1]);
    strcpy(file, argv[2]);
  } else {
    group = 0;
    strcpy(file, "/test/file");
  }
  if ((talpa = vc_init(group, tout * 1000)) < 0) {
    fprintf(stderr, "Failed to initialize!\n");
    return -1;
  }
  rc = fork();
  if (!rc) {
    int fd = open(file, O_RDONLY);
    if ((fd < 0) && (errno == ETIME)) {
      return 0;
    }
    return -1;
  } else if (rc < 0) {
    fprintf(stderr, "Fork failed!\n");
    return -1;
  }
  details = vc_get(talpa);
  if (!details) {
    fprintf(stderr, "Nothing caught!\n");
    vc_exit(talpa);
    wait(NULL);
    return -1;
  }
  wait(&status);
  if (!WIFEXITED(status)) {
    fprintf(stderr, "Child error!\n");
    vc_exit(talpa);
    return -1;
  }
  if (WEXITSTATUS(status)) {
    fprintf(stderr, "Child open failed!\n");
    vc_exit(talpa);
    return -1;
  }
  vc_exit(talpa);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1200 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
jmp    1217 <main+0x67>
movl   $0x0,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
mov    $0x7d0,%esi
call   1040 <vc_init@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
jge    1254 <main+0xa4>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ec <main+0x23c>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jne    12c5 <main+0x115>
lea    -0x80(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jge    12b9 <main+0x109>
mov    0x2d2e(%rip),%rax
mov    (%rax),%rax
mov    0x2d3c(%rip),%rcx
cmp    (%rcx),%rax
jne    12b9 <main+0x109>
movl   $0x0,-0x4(%rbp)
jmp    13ec <main+0x23c>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ec <main+0x23c>
cmpl   $0x0,-0x88(%rbp)
jge    12f3 <main+0x143>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ec <main+0x23c>
jmp    12f8 <main+0x148>
mov    -0x84(%rbp),%edi
call   1080 <vc_get@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jne    134d <main+0x19d>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x84(%rbp),%edi
call   10d0 <vc_exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ec <main+0x23c>
lea    -0x94(%rbp),%rdi
call   10b0 <wait@plt>
mov    -0x94(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    1399 <main+0x1e9>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
lea    0xcc4(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x84(%rbp),%edi
call   10d0 <vc_exit@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ec <main+0x23c>
mov    -0x94(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     13da <main+0x22a>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
lea    0xc91(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x84(%rbp),%edi
call   10d0 <vc_exit@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ec <main+0x23c>
mov    -0x84(%rbp),%edi
call   10d0 <vc_exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
cmp    $0x2,%edi
jl     11cf <main+0x1f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rsi
jmp    11d8 <main+0x28>
xor    %ebp,%ebp
lea    0xe28(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    $0x7d0,%esi
call   1040 <vc_init@plt>
test   %eax,%eax
js     1257 <main+0xa7>
mov    %eax,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1269 <main+0xb9>
js     129a <main+0xea>
mov    %ebx,%edi
call   1080 <vc_get@plt>
test   %rax,%rax
je     12bb <main+0x10b>
lea    0xc(%rsp),%rdi
call   10b0 <wait@plt>
mov    0xc(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %eax,%eax
je     12e0 <main+0x130>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
test   %rax,%rax
je     12fe <main+0x14e>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
jmp    12f0 <main+0x140>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
jmp    12aa <main+0xfa>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1070 <open@plt>
test   %eax,%eax
jns    12af <main+0xff>
mov    0x2d41(%rip),%rax
mov    (%rax),%rcx
mov    0x2d4f(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
jne    12af <main+0xff>
jmp    12b4 <main+0x104>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xd65(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   10d0 <vc_exit@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
jmp    12af <main+0xff>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   10d0 <vc_exit@plt>
jmp    12af <main+0xff>
mov    %ebx,%edi
call   10d0 <vc_exit@plt>
xor    %eax,%eax
jmp    12b4 <main+0x104>

LLVM IR (-O0):
%struct.TalpaPacket_VettingDetails = type { i32 }
@.str = [11 x i8] c"/test/file\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Failed to initialize!\0A\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ETIME = global i64 0
@.str.2 = [14 x i8] c"Fork failed!\0A\00"
@.str.3 = [17 x i8] c"Nothing caught!\0A\00"
@.str.4 = [14 x i8] c"Child error!\0A\00"
@.str.5 = [20 x i8] c"Child open failed!\0A\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 [100 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TalpaPacket_VettingDetails*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %7
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %26
16: ; preds = %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* %6
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
br label %29
26: ; preds = %2
store i32 0, i32* %6
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %26, %16
%30 = load i32, i32* %6
%31 = call i32 @vc_init(i32 %30, i32 2000)
store i32 %31, i32* %9
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %92
36: ; preds = %29
%37 = call i32 (...) @fork()
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp ne i32 %38, 0
br i1 %39, label %52, label %40
40: ; preds = %36
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* %41, i32 %42)
store i32 %43, i32* %13
%44 = load i32, i32* %13
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %40
%47 = load i64, i64* @errno
%48 = load i64, i64* @ETIME
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 0, i32* %3
br label %92
51: ; preds = %46, %40
store i32 -1, i32* %3
br label %92
52: ; preds = %36
%53 = load i32, i32* %10
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %92
58: ; preds = %52
br label %59
59: ; preds = %58
%60 = load i32, i32* %9
%61 = call %struct.TalpaPacket_VettingDetails* @vc_get(i32 %60)
store %struct.TalpaPacket_VettingDetails* %61, %struct.TalpaPacket_VettingDetails** %11
%62 = load %struct.TalpaPacket_VettingDetails*, %struct.TalpaPacket_VettingDetails** %11
%63 = icmp ne %struct.TalpaPacket_VettingDetails* %62, null
br i1 %63, label %70, label %64
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* %9
%68 = call i32 @vc_exit(i32 %67)
%69 = call i32 @wait(i32* null)
store i32 -1, i32* %3
br label %92
70: ; preds = %59
%71 = call i32 @wait(i32* %12)
%72 = load i32, i32* %12
%73 = call i32 @WIFEXITED(i32 %72)
%74 = icmp ne i32 %73, 0
br i1 %74, label %80, label %75
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* %9
%79 = call i32 @vc_exit(i32 %78)
store i32 -1, i32* %3
br label %92
80: ; preds = %70
%81 = load i32, i32* %12
%82 = call i64 @WEXITSTATUS(i32 %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %80
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%87 = load i32, i32* %9
%88 = call i32 @vc_exit(i32 %87)
store i32 -1, i32* %3
br label %92
89: ; preds = %80
%90 = load i32, i32* %9
%91 = call i32 @vc_exit(i32 %90)
store i32 0, i32* %3
br label %92
92: ; preds = %89, %84, %75, %64, %55, %51, %50, %33
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.TalpaPacket_VettingDetails = type { i32 }
@.str = [11 x i8] c"/test/file\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Failed to initialize!\0A\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ETIME = global i64 0
@.str.2 = [14 x i8] c"Fork failed!\0A\00"
@.str.3 = [17 x i8] c"Nothing caught!\0A\00"
@.str.4 = [14 x i8] c"Child error!\0A\00"
@.str.5 = [20 x i8] c"Child open failed!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
br label %14
14: ; preds = %2, %8
%15 = phi i8* [ %13, %8 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%16 = phi i32 [ %11, %8 ], [ 0, %2 ]
%17 = call i32 @strcpy(i8* %5, i8* %15)
%18 = call i32 @vc_init(i32 %16, i32 2000)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %67
23: ; preds = %14
%24 = call i32 (...) @fork()
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %5, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i64, i64* @errno
%32 = load i64, i64* @ETIME
%33 = icmp eq i64 %31, %32
br i1 %33, label %67, label %34
34: ; preds = %30, %26
br label %67
35: ; preds = %23
%36 = icmp slt i32 %24, 0
br i1 %36, label %37, label %40
37: ; preds = %35
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %67
40: ; preds = %35
%41 = call %struct.TalpaPacket_VettingDetails* @vc_get(i32 %18)
%42 = icmp eq %struct.TalpaPacket_VettingDetails* %41, null
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @vc_exit(i32 %18)
%47 = call i32 @wait(i32* null)
br label %67
48: ; preds = %40
%49 = call i32 @wait(i32* %4)
%50 = load i32, i32* %4
%51 = call i32 @WIFEXITED(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @vc_exit(i32 %18)
br label %67
57: ; preds = %48
%58 = load i32, i32* %4
%59 = call i64 @WEXITSTATUS(i32 %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%64 = call i32 @vc_exit(i32 %18)
br label %67
65: ; preds = %57
%66 = call i32 @vc_exit(i32 %18)
br label %67
67: ; preds = %34, %30, %65, %61, %53, %43, %37, %20
%68 = phi i32 [ -1, %20 ], [ -1, %37 ], [ -1, %61 ], [ 0, %65 ], [ -1, %53 ], [ -1, %43 ], [ -1, %34 ], [ 0, %30 ]
ret i32 %68
}