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

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ LOG_PERROR;
int /*<<< orphan*/ LOG_USER;
int add_pinhole(char *, char *, int, char *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ clean_pinhole_list(int /*<<< orphan*/ *);
int delete_pinhole(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ init_redirect();
int /*<<< orphan*/ openlog(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ print_pinhole(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int uid;
  int ret;
  openlog("testpfpinhole", LOG_PERROR, LOG_USER);
  if (init_redirect() < 0) {
    fprintf(stderr, "init_redirect() failed\n");
    return 1;
  }
  uid = add_pinhole("ep0", "2001::1:2:3", 12345, "123::ff", 54321, IPPROTO_UDP,
                    424242);
  if (uid < 0) {
    fprintf(stderr, "add_pinhole() failed\n");
  }
  printf("add_pinhole() returned %d\n", uid);
  uid = add_pinhole("ep0", NULL, 0, "dead:beef::42:42", 8080, IPPROTO_UDP,
                    4321000);
  if (uid < 0) {
    fprintf(stderr, "add_pinhole() failed\n");
  }
  printf("add_pinhole() returned %d\n", uid);
  print_pinhole(1);
  print_pinhole(2);
  clean_pinhole_list(NULL);
  ret = delete_pinhole(1);
  printf("delete_pinhole() returned %d\n", ret);
  ret = delete_pinhole(2);
  printf("delete_pinhole() returned %d\n", ret);
  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)
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
lea    0xe51(%rip),%rdi
call   1080 <openlog@plt>
mov    $0x0,%al
call   1030 <init_redirect@plt>
cmp    $0x0,%rax
jge    11e6 <main+0x66>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130a <main+0x18a>
mov    0x2dd3(%rip),%rax
mov    (%rax),%r9d
lea    0xe2f(%rip),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x3039,%edx
lea    0xe2c(%rip),%rcx
mov    $0xd431,%r8d
movl   $0x67932,(%rsp)
call   1060 <add_pinhole@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123e <main+0xbe>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%r9d
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
lea    0xe04(%rip),%rcx
mov    $0x1f90,%r8d
movl   $0x41eee8,(%rsp)
call   1060 <add_pinhole@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    129f <main+0x11f>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%esi
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <print_pinhole@plt>
mov    $0x2,%edi
call   10a0 <print_pinhole@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <clean_pinhole_list@plt>
mov    $0x1,%edi
call   1070 <delete_pinhole@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd9e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <delete_pinhole@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd82(%rip),%rdi
call   1040 <printf@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    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
lea    0xe64(%rip),%rdi
call   1080 <openlog@plt>
xor    %eax,%eax
call   1030 <init_redirect@plt>
test   %rax,%rax
js     12b0 <main+0x130>
mov    0x2e08(%rip),%rbp
mov    0x0(%rbp),%r9d
movl   $0x67932,(%rsp)
lea    0xe5c(%rip),%rdi
lea    0xe59(%rip),%rsi
lea    0xe5e(%rip),%rcx
mov    $0x3039,%edx
mov    $0xd431,%r8d
call   1060 <add_pinhole@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1203 <main+0x83>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe4a(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    0x0(%rbp),%r9d
movl   $0x41eee8,(%rsp)
lea    0xe03(%rip),%rdi
lea    0xe45(%rip),%rcx
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
mov    $0x1f90,%r8d
call   1060 <add_pinhole@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1256 <main+0xd6>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xdf7(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <print_pinhole@plt>
mov    $0x2,%edi
call   10a0 <print_pinhole@plt>
xor    %edi,%edi
call   1090 <clean_pinhole_list@plt>
mov    $0x1,%edi
call   1070 <delete_pinhole@plt>
lea    0xdf0(%rip),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1070 <delete_pinhole@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
jmp    12ca <main+0x14a>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"testpfpinhole\00"
@LOG_PERROR = global i32 0
@LOG_USER = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"init_redirect() failed\0A\00"
@.str.2 = [4 x i8] c"ep0\00"
@.str.3 = [12 x i8] c"2001::1:2:3\00"
@.str.4 = [8 x i8] c"123::ff\00"
@IPPROTO_UDP = global i32 0
@.str.5 = [22 x i8] c"add_pinhole() failed\0A\00"
@.str.6 = [27 x i8] c"add_pinhole() returned %d\0A\00"
@.str.7 = [17 x i8] c"dead:beef::42:42\00"
@.str.8 = [30 x i8] c"delete_pinhole() returned %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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @LOG_PERROR
%9 = load i32, i32* @LOG_USER
%10 = call i32 @openlog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = call i64 (...) @init_redirect()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %46
16: ; preds = %2
%17 = load i32, i32* @IPPROTO_UDP
%18 = call i32 @add_pinhole(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 12345, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 54321, i32 %17, i32 424242)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %21, %16
%25 = load i32, i32* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @IPPROTO_UDP
%28 = call i32 @add_pinhole(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* null, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 8080, i32 %27, i32 4321000)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %31, %24
%35 = load i32, i32* %6
%36 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = call i32 @print_pinhole(i32 1)
%38 = call i32 @print_pinhole(i32 2)
%39 = call i32 @clean_pinhole_list(i32* null)
%40 = call i32 @delete_pinhole(i32 1)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %41)
%43 = call i32 @delete_pinhole(i32 2)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %44)
store i32 0, i32* %3
br label %46
46: ; preds = %34, %13
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"testpfpinhole\00"
@LOG_PERROR = global i32 0
@LOG_USER = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"init_redirect() failed\0A\00"
@.str.2 = [4 x i8] c"ep0\00"
@.str.3 = [12 x i8] c"2001::1:2:3\00"
@.str.4 = [8 x i8] c"123::ff\00"
@IPPROTO_UDP = global i32 0
@.str.5 = [22 x i8] c"add_pinhole() failed\0A\00"
@.str.6 = [27 x i8] c"add_pinhole() returned %d\0A\00"
@.str.7 = [17 x i8] c"dead:beef::42:42\00"
@.str.8 = [30 x i8] c"delete_pinhole() returned %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @LOG_PERROR
%4 = load i32, i32* @LOG_USER
%5 = tail call i32 @openlog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = tail call i64 (...) @init_redirect()
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %35
11: ; preds = %2
%12 = load i32, i32* @IPPROTO_UDP
%13 = tail call i32 @add_pinhole(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 12345, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 54321, i32 %12, i32 424242)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %15, %11
%19 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %13)
%20 = load i32, i32* @IPPROTO_UDP
%21 = tail call i32 @add_pinhole(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* null, i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 8080, i32 %20, i32 4321000)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %23, %18
%27 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%28 = tail call i32 @print_pinhole(i32 1)
%29 = tail call i32 @print_pinhole(i32 2)
%30 = tail call i32 @clean_pinhole_list(i32* null)
%31 = tail call i32 @delete_pinhole(i32 1)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %31)
%33 = tail call i32 @delete_pinhole(i32 2)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %26, %8
%36 = phi i32 [ 1, %8 ], [ 0, %26 ]
ret i32 %36
}