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

/* Variables and functions */
int abs(scalar_t__);
unsigned int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ vc_exit(int);
struct TalpaPacket_VettingDetails *vc_get(int);
int vc_init(unsigned int, unsigned int const);
int main(int argc, char *argv[]) {
  unsigned int group;
  const unsigned int tout = 2;
  int talpa;
  struct TalpaPacket_VettingDetails *details;
  time_t start;
  time_t end;
  if (argc == 2)
    group = atoi(argv[1]);
  else
    group = 0;
  if ((talpa = vc_init(group, tout * 1000)) < 0) {
    fprintf(stderr, "Failed to initialize!\n");
    return -1;
  }
  start = time(NULL);
  while (time(NULL) == start)
    ;
  start = time(NULL);
  details = vc_get(talpa);
  end = time(NULL);
  if (details) {
    fprintf(stderr, "Unexpected interception!\n");
    vc_exit(talpa);
    return -1;
  }
  if (!((tout - 1) <= abs(end - start) && abs(end - start) <= (tout + 1))) {
    fprintf(stderr, "Timeout error (%d (%d))!\n", abs(end - start), tout);
    vc_exit(talpa);
    return -1;
  }
  vc_exit(talpa);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11ac <main+0x3c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11b3 <main+0x43>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x7d0,%esi
call   1040 <vc_init@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11ef <main+0x7f>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <main+0x186>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
cmp    -0x30(%rbp),%rax
jne    1214 <main+0xa4>
jmp    11fc <main+0x8c>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <vc_get@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1270 <main+0x100>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <vc_exit@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <main+0x186>
mov    -0x38(%rbp),%rdi
sub    -0x30(%rbp),%rdi
call   1030 <abs@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
ja     12a2 <main+0x132>
mov    -0x38(%rbp),%rdi
sub    -0x30(%rbp),%rdi
call   1030 <abs@plt>
cmp    $0x3,%eax
jbe    12e7 <main+0x177>
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
sub    -0x30(%rbp),%rdi
call   1030 <abs@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%edx
lea    0xd6a(%rip),%rsi
mov    $0x2,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <vc_exit@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f6 <main+0x186>
mov    -0x1c(%rbp),%edi
call   1090 <vc_exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%eax
xor    %edi,%edi
cmp    $0x2,%eax
jne    118b <main+0x1b>
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
mov    $0x7d0,%esi
call   1040 <vc_init@plt>
test   %eax,%eax
js     11f6 <main+0x86>
mov    %eax,%r15d
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
call   1060 <time@plt>
cmp    %rbx,%rax
je     11b0 <main+0x40>
xor    %edi,%edi
call   1060 <time@plt>
mov    %rax,%r14
mov    %r15d,%edi
call   1070 <vc_get@plt>
mov    %rax,%rbp
xor    %edi,%edi
call   1060 <time@plt>
test   %rbp,%rbp
je     120f <main+0x9f>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1262 <main+0xf2>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    126a <main+0xfa>
mov    %rax,%rbx
sub    %r14,%rbx
mov    %rbx,%rdi
call   1030 <abs@plt>
test   %eax,%eax
je     123a <main+0xca>
mov    %rbx,%rdi
call   1030 <abs@plt>
cmp    $0x4,%eax
jae    123a <main+0xca>
mov    %r15d,%edi
call   1090 <vc_exit@plt>
xor    %eax,%eax
jmp    126f <main+0xff>
mov    0x2d9f(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1030 <abs@plt>
lea    0xddf(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
mov    $0x2,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15d,%edi
call   1090 <vc_exit@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TalpaPacket_VettingDetails = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Failed to initialize!\0A\00"
@.str.1 = [26 x i8] c"Unexpected interception!\0A\00"
@.str.2 = [26 x i8] c"Timeout error (%d (%d))!\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 i32
%9 = alloca %struct.TalpaPacket_VettingDetails*
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %7
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
br label %20
19: ; preds = %2
store i32 0, i32* %6
br label %20
20: ; preds = %19, %14
%21 = load i32, i32* %6
%22 = call i32 @vc_init(i32 %21, i32 2000)
store i32 %22, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
27: ; preds = %20
%28 = call i64 @time(i32* null)
store i64 %28, i64* %10
br label %29
29: ; preds = %33, %27
%30 = call i64 @time(i32* null)
%31 = load i64, i64* %10
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
br label %29
34: ; preds = %29
%35 = call i64 @time(i32* null)
store i64 %35, i64* %10
%36 = load i32, i32* %8
%37 = call %struct.TalpaPacket_VettingDetails* @vc_get(i32 %36)
store %struct.TalpaPacket_VettingDetails* %37, %struct.TalpaPacket_VettingDetails** %9
%38 = call i64 @time(i32* null)
store i64 %38, i64* %11
%39 = load %struct.TalpaPacket_VettingDetails*, %struct.TalpaPacket_VettingDetails** %9
%40 = icmp ne %struct.TalpaPacket_VettingDetails* %39, null
br i1 %40, label %41, label %46
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* %8
%45 = call i32 @vc_exit(i32 %44)
store i32 -1, i32* %3
br label %70
46: ; preds = %34
%47 = load i64, i64* %11
%48 = load i64, i64* %10
%49 = sub nsw i64 %47, %48
%50 = call i32 @abs(i64 %49)
%51 = icmp ule i32 1, %50
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = load i64, i64* %11
%54 = load i64, i64* %10
%55 = sub nsw i64 %53, %54
%56 = call i32 @abs(i64 %55)
%57 = icmp ule i32 %56, 3
br i1 %57, label %67, label %58
58: ; preds = %52, %46
%59 = load i32, i32* @stderr
%60 = load i64, i64* %11
%61 = load i64, i64* %10
%62 = sub nsw i64 %60, %61
%63 = call i32 @abs(i64 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %63, i32 2)
%65 = load i32, i32* %8
%66 = call i32 @vc_exit(i32 %65)
store i32 -1, i32* %3
br label %70
67: ; preds = %52
%68 = load i32, i32* %8
%69 = call i32 @vc_exit(i32 %68)
store i32 0, i32* %3
br label %70
70: ; preds = %67, %58, %41, %24
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.TalpaPacket_VettingDetails = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Failed to initialize!\0A\00"
@.str.1 = [26 x i8] c"Unexpected interception!\0A\00"
@.str.2 = [26 x i8] c"Timeout error (%d (%d))!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 0, %2 ]
%10 = tail call i32 @vc_init(i32 %9, i32 2000)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %43
15: ; preds = %8
%16 = tail call i64 @time(i32* null)
br label %17
17: ; preds = %17, %15
%18 = tail call i64 @time(i32* null)
%19 = icmp eq i64 %18, %16
br i1 %19, label %17, label %20
20: ; preds = %17
%21 = tail call i64 @time(i32* null)
%22 = tail call %struct.TalpaPacket_VettingDetails* @vc_get(i32 %10)
%23 = tail call i64 @time(i32* null)
%24 = icmp eq %struct.TalpaPacket_VettingDetails* %22, null
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%28 = tail call i32 @vc_exit(i32 %10)
br label %43
29: ; preds = %20
%30 = sub nsw i64 %23, %21
%31 = tail call i32 @abs(i64 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = tail call i32 @abs(i64 %30)
%35 = icmp ult i32 %34, 4
br i1 %35, label %41, label %36
36: ; preds = %33, %29
%37 = load i32, i32* @stderr
%38 = tail call i32 @abs(i64 %30)
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 2)
%40 = tail call i32 @vc_exit(i32 %10)
br label %43
41: ; preds = %33
%42 = tail call i32 @vc_exit(i32 %10)
br label %43
43: ; preds = %41, %36, %25, %12
%44 = phi i32 [ -1, %12 ], [ -1, %25 ], [ 0, %41 ], [ -1, %36 ]
ret i32 %44
}