#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 */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
unsigned int atoi(char *);
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) {
      return 0;
    }
    return -1;
  } else if (rc < 0) {
    fprintf(stderr, "Fork failed!\n");
    return -1;
  }
  details = vc_get(talpa);
  if (details) {
    fprintf(stderr, "Caught something unexpectedly!\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    0x2d9e(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d2 <main+0x222>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jne    12ab <main+0xfb>
lea    -0x80(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jle    129f <main+0xef>
movl   $0x0,-0x4(%rbp)
jmp    13d2 <main+0x222>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d2 <main+0x222>
cmpl   $0x0,-0x88(%rbp)
jge    12d9 <main+0x129>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d2 <main+0x222>
jmp    12de <main+0x12e>
mov    -0x84(%rbp),%edi
call   1080 <vc_get@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
je     1333 <main+0x183>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%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    13d2 <main+0x222>
lea    -0x94(%rbp),%rdi
call   10b0 <wait@plt>
mov    -0x94(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    137f <main+0x1cf>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x84(%rbp),%edi
call   10d0 <vc_exit@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d2 <main+0x222>
mov    -0x94(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     13c0 <main+0x210>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
lea    0xcba(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x84(%rbp),%edi
call   10d0 <vc_exit@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d2 <main+0x222>
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     1232 <main+0x82>
mov    %eax,%ebx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1244 <main+0x94>
js     1264 <main+0xb4>
mov    %ebx,%edi
call   1080 <vc_get@plt>
test   %rax,%rax
je     1285 <main+0xd5>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   10d0 <vc_exit@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
jmp    1279 <main+0xc9>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
jmp    1274 <main+0xc4>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1070 <open@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setle  %al
neg    %eax
jmp    127e <main+0xce>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xc(%rsp),%rdi
call   10b0 <wait@plt>
mov    0xc(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %eax,%eax
je     12bc <main+0x10c>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
test   %rax,%rax
je     12da <main+0x12a>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
jmp    12cc <main+0x11c>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
call   1050 <fprintf@plt>
mov    %ebx,%edi
call   10d0 <vc_exit@plt>
jmp    1279 <main+0xc9>
mov    %ebx,%edi
call   10d0 <vc_exit@plt>
xor    %eax,%eax
jmp    127e <main+0xce>

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
@.str.2 = [14 x i8] c"Fork failed!\0A\00"
@.str.3 = [32 x i8] c"Caught something unexpectedly!\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 %88
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 %48, 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 sgt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 0, i32* %3
br label %88
47: ; preds = %40
store i32 -1, i32* %3
br label %88
48: ; preds = %36
%49 = load i32, i32* %10
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %88
54: ; preds = %48
br label %55
55: ; preds = %54
%56 = load i32, i32* %9
%57 = call %struct.TalpaPacket_VettingDetails* @vc_get(i32 %56)
store %struct.TalpaPacket_VettingDetails* %57, %struct.TalpaPacket_VettingDetails** %11
%58 = load %struct.TalpaPacket_VettingDetails*, %struct.TalpaPacket_VettingDetails** %11
%59 = icmp ne %struct.TalpaPacket_VettingDetails* %58, null
br i1 %59, label %60, label %66
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* %9
%64 = call i32 @vc_exit(i32 %63)
%65 = call i32 @wait(i32* null)
store i32 -1, i32* %3
br label %88
66: ; preds = %55
%67 = call i32 @wait(i32* %12)
%68 = load i32, i32* %12
%69 = call i32 @WIFEXITED(i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %76, label %71
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* %9
%75 = call i32 @vc_exit(i32 %74)
store i32 -1, i32* %3
br label %88
76: ; preds = %66
%77 = load i32, i32* %12
%78 = call i64 @WEXITSTATUS(i32 %77)
%79 = icmp ne i64 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %76
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32, i32* %9
%84 = call i32 @vc_exit(i32 %83)
store i32 -1, i32* %3
br label %88
85: ; preds = %76
%86 = load i32, i32* %9
%87 = call i32 @vc_exit(i32 %86)
store i32 0, i32* %3
br label %88
88: ; preds = %85, %80, %71, %60, %51, %47, %46, %33
%89 = load i32, i32* %3
ret i32 %89
}

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
@.str.2 = [14 x i8] c"Fork failed!\0A\00"
@.str.3 = [32 x i8] c"Caught something unexpectedly!\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 %63
23: ; preds = %14
%24 = call i32 (...) @fork()
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %5, i32 %27)
%29 = icmp slt i32 %28, 1
%30 = sext i1 %29 to i32
br label %63
31: ; preds = %23
%32 = icmp slt i32 %24, 0
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %63
36: ; preds = %31
%37 = call %struct.TalpaPacket_VettingDetails* @vc_get(i32 %18)
%38 = icmp eq %struct.TalpaPacket_VettingDetails* %37, null
br i1 %38, label %44, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @vc_exit(i32 %18)
%43 = call i32 @wait(i32* null)
br label %63
44: ; preds = %36
%45 = call i32 @wait(i32* %4)
%46 = load i32, i32* %4
%47 = call i32 @WIFEXITED(i32 %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @vc_exit(i32 %18)
br label %63
53: ; preds = %44
%54 = load i32, i32* %4
%55 = call i64 @WEXITSTATUS(i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%60 = call i32 @vc_exit(i32 %18)
br label %63
61: ; preds = %53
%62 = call i32 @vc_exit(i32 %18)
br label %63
63: ; preds = %61, %57, %49, %39, %33, %26, %20
%64 = phi i32 [ -1, %20 ], [ -1, %33 ], [ -1, %39 ], [ -1, %57 ], [ 0, %61 ], [ -1, %49 ], [ %30, %26 ]
ret i32 %64
}