#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 */
scalar_t__ close(int);
int /*<<< orphan*/ perror_and_exit(char *);
scalar_t__ socks5_auth(int);
scalar_t__ socks5_connect(int, int *);
int /*<<< orphan*/ transfer_data(int, int);
void socks5(int client_sockfd) {
  do {
    if (socks5_auth(client_sockfd))
      break;
    int connect_sockfd;
    if (socks5_connect(client_sockfd, &connect_sockfd))
      break;
    transfer_data(client_sockfd, connect_sockfd);
    if (close(connect_sockfd))
      perror_and_exit("close");
  } while (false);
  if (close(client_sockfd))
    perror_and_exit("close");
}


x86 assembly (clang, -O0):
<socks5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <socks5_auth@plt>
cmp    $0x0,%rax
je     1172 <socks5+0x22>
jmp    11bb <socks5+0x6b>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1060 <socks5_connect@plt>
cmp    $0x0,%rax
je     118d <socks5+0x3d>
jmp    11bb <socks5+0x6b>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <transfer_data@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     11b6 <socks5+0x66>
lea    0xe4f(%rip),%rdi
call   1070 <perror_and_exit@plt>
jmp    11bb <socks5+0x6b>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     11d9 <socks5+0x89>
lea    0xe2c(%rip),%rdi
call   1070 <perror_and_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socks5>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   1030 <socks5_auth@plt>
test   %rax,%rax
jne    1197 <socks5+0x47>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1060 <socks5_connect@plt>
test   %rax,%rax
jne    1197 <socks5+0x47>
mov    0xc(%rsp),%esi
mov    %ebx,%edi
call   1040 <transfer_data@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
je     1197 <socks5+0x47>
lea    0xe6e(%rip),%rdi
call   1070 <perror_and_exit@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   %rax,%rax
je     11af <socks5+0x5f>
lea    0xe56(%rip),%rdi
call   1070 <perror_and_exit@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"close\00"
define void @socks5(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
br label %4
4: ; preds = %1
%5 = load i32, i32* %2
%6 = call i64 @socks5_auth(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %24
9: ; preds = %4
%10 = load i32, i32* %2
%11 = call i64 @socks5_connect(i32 %10, i32* %3)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
br label %24
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 @transfer_data(i32 %15, i32 %16)
%18 = load i32, i32* %3
%19 = call i64 @close(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @perror_and_exit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
br label %24
24: ; preds = %23, %13, %8
%25 = load i32, i32* %2
%26 = call i64 @close(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror_and_exit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"close\00"
define void @socks5(i32 %0) {
%2 = alloca i32
%3 = tail call i64 @socks5_auth(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
%7 = call i64 @socks5_connect(i32 %0, i32* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i32, i32* %2
%11 = call i32 @transfer_data(i32 %0, i32 %10)
%12 = load i32, i32* %2
%13 = call i64 @close(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = call i32 @perror_and_exit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %9, %15, %5
br label %18
18: ; preds = %17, %1
%19 = call i64 @close(i32 %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @perror_and_exit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
ret void
}