#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 pproxy {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ pproxy_get_port(struct pproxy *, short *);
scalar_t__ pproxy_init(struct pproxy **, char *, int);
int pproxy_start(struct pproxy *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct pproxy *handle = 0;
  if (pproxy_init(&handle, "127.0.0.1", 31337)) {
    fprintf(stderr, "Failed to initialize pproxy\n");
    exit(1);
  }
  short port = 0;
  if (pproxy_get_port(handle, &port)) {
    fprintf(stderr, "Failed to retrieve bound port\n");
    exit(1);
  }
  printf("pproxy is listening on 127.0.0.1:%hu\n", port);
  int rc = pproxy_start(handle);
  printf("pproxy exited with %d\n", rc);
  return rc;
}


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)
movq   $0x0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x7a69,%edx
call   1060 <pproxy_init@plt>
cmp    $0x0,%rax
je     11bc <main+0x5c>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movw   $0x0,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1030 <pproxy_get_port@plt>
cmp    $0x0,%rax
je     11f8 <main+0x98>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movswl -0x1a(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <pproxy_start@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe8b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    $0x7a69,%edx
call   1060 <pproxy_init@plt>
test   %rax,%rax
jne    11d7 <main+0x77>
movw   $0x0,0x6(%rsp)
mov    0x8(%rsp),%rdi
lea    0x6(%rsp),%rsi
call   1030 <pproxy_get_port@plt>
test   %rax,%rax
jne    11e9 <main+0x89>
movswl 0x6(%rsp),%esi
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1080 <pproxy_start@plt>
mov    %eax,%ebx
lea    0xea4(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
jmp    11f9 <main+0x99>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.pproxy = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Failed to initialize pproxy\0A\00"
@.str.2 = [31 x i8] c"Failed to retrieve bound port\0A\00"
@.str.3 = [38 x i8] c"pproxy is listening on 127.0.0.1:%hu\0A\00"
@.str.4 = [23 x i8] c"pproxy exited with %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.pproxy*
%7 = alloca i16
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.pproxy* null, %struct.pproxy** %6
%9 = call i64 @pproxy_init(%struct.pproxy** %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 31337)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
store i16 0, i16* %7
%16 = load %struct.pproxy*, %struct.pproxy** %6
%17 = call i64 @pproxy_get_port(%struct.pproxy* %16, i16* %7)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = load i16, i16* %7
%25 = sext i16 %24 to i32
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load %struct.pproxy*, %struct.pproxy** %6
%28 = call i32 @pproxy_start(%struct.pproxy* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %8
ret i32 %31
}

LLVM IR (-O2):
%struct.pproxy = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Failed to initialize pproxy\0A\00"
@.str.2 = [31 x i8] c"Failed to retrieve bound port\0A\00"
@.str.3 = [38 x i8] c"pproxy is listening on 127.0.0.1:%hu\0A\00"
@.str.4 = [23 x i8] c"pproxy exited with %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.pproxy*
%4 = alloca i16
%5 = bitcast %struct.pproxy** %3 to i8*
store %struct.pproxy* null, %struct.pproxy** %3
%6 = call i64 @pproxy_init(%struct.pproxy** %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 31337)
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%14 = load %struct.pproxy*, %struct.pproxy** %3
%15 = call i64 @pproxy_get_port(%struct.pproxy* %14, i16* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i16, i16* %4
%23 = sext i16 %22 to i32
%24 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load %struct.pproxy*, %struct.pproxy** %3
%26 = call i32 @pproxy_start(%struct.pproxy* %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %26)
ret i32 %26
}