#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 bs_socks5_auth(int);
int bs_socks5_command(int);
int bs_socks5_method(int);
int /*<<< orphan*/ bs_socks5_process(int, int);
int /*<<< orphan*/ close(int);
int bs_socks5(void *client_sock) {
  int sock = *(int *)client_sock;
  if (bs_socks5_method(sock) == -1) {
    return -1;
  }
  if (bs_socks5_auth(sock) == -1) {
    return -1;
  }
  int real_server_sock = bs_socks5_command(sock);
  if (real_server_sock == -1) {
    return -1;
  }
  bs_socks5_process(sock, real_server_sock);
  close(sock);
  close(real_server_sock);
  return 0;
}


x86 assembly (clang, -O0):
<bs_socks5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <bs_socks5_method@plt>
cmp    $0xffffffff,%eax
jne    1182 <bs_socks5+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <bs_socks5+0x92>
mov    -0x14(%rbp),%edi
call   1030 <bs_socks5_auth@plt>
cmp    $0xffffffff,%eax
jne    119f <bs_socks5+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <bs_socks5+0x92>
mov    -0x14(%rbp),%edi
call   1070 <bs_socks5_command@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c0 <bs_socks5+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <bs_socks5+0x92>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <bs_socks5_process@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bs_socks5>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%ebx
mov    %ebx,%edi
call   1050 <bs_socks5_method@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     119c <bs_socks5+0x4c>
mov    %ebx,%edi
call   1030 <bs_socks5_auth@plt>
cmp    $0xffffffff,%eax
je     119c <bs_socks5+0x4c>
mov    %ebx,%edi
call   1070 <bs_socks5_command@plt>
cmp    $0xffffffff,%eax
je     119c <bs_socks5+0x4c>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <bs_socks5_process@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bs_socks5(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = call i32 @bs_socks5_method(i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %32
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call i32 @bs_socks5_auth(i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %2
br label %32
18: ; preds = %13
%19 = load i32, i32* %4
%20 = call i32 @bs_socks5_command(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 -1, i32* %2
br label %32
24: ; preds = %18
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 @bs_socks5_process(i32 %25, i32 %26)
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
store i32 0, i32* %2
br label %32
32: ; preds = %24, %23, %17, %12
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @bs_socks5(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @bs_socks5_method(i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = tail call i32 @bs_socks5_auth(i32 %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = tail call i32 @bs_socks5_command(i32 %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i32 @bs_socks5_process(i32 %3, i32 %10)
%14 = tail call i32 @close(i32 %3)
%15 = tail call i32 @close(i32 %10)
br label %16
16: ; preds = %12, %9, %6, %1
%17 = phi i32 [ -1, %1 ], [ -1, %6 ], [ 0, %12 ], [ -1, %9 ]
ret i32 %17
}