#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socksaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int build_socks4a_resolve_request(char **, char *, char const *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ parse_socks4a_resolve_response(char *, int, int /*<<< orphan*/ *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ show_msg(int, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int do_resolve(const char *hostname, uint32_t sockshost, uint16_t socksport,
               uint32_t *result_addr) {
  int s;
  struct sockaddr_in socksaddr;
  char *req, *cp;
  int r, len;
  char response_buf[8];
  show_msg(2, "do_resolve: resolving %s\n", hostname);
  s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (s < 0) {
    show_msg(1, "do_resolve: problem creating socket\n");
    return -1;
  }
  memset(&socksaddr, 0, sizeof(socksaddr));
  socksaddr.sin_family = AF_INET;
  socksaddr.sin_port = htons(socksport);
  socksaddr.sin_addr.s_addr = htonl(sockshost);
  if (connect(s, (struct sockaddr *)&socksaddr, sizeof(socksaddr))) {
    show_msg(1, "do_resolve: error connecting to SOCKS server\n");
    return -1;
  }
  if ((len = build_socks4a_resolve_request(&req, "", hostname)) < 0) {
    show_msg(1, "do_resolve: error generating SOCKS request\n");
    return -1;
  }
  cp = req;
  while (len) {
    r = (int)send(s, cp, len, 0);
    if (r < 0) {
      show_msg(1, "do_resolve: error sending SOCKS request\n");
      free(req);
      return -1;
    }
    len -= r;
    cp += r;
  }
  free(req);
  len = 0;
  while (len < 8) {
    r = (int)recv(s, response_buf + len, 8 - len, 0);
    if (r == 0) {
      show_msg(1, "do_resolve: EOF while reading SOCKS response\n");
      return -1;
    }
    if (r < 0) {
      show_msg(1, "do_resolve: error reading SOCKS response\n");
      return -1;
    }
    len += r;
  }
  close(s);
  if (parse_socks4a_resolve_response(response_buf, 8, result_addr) < 0) {
    show_msg(1, "do_resolve: error parsing SOCKS response\n");
    return -1;
  }
  show_msg(2, "do_resolve: success\n");
  return 0;
}


x86 assembly (clang, -O0):
<do_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x2,%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1239 <do_resolve+0x79>
mov    $0x1,%edi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
je     12a5 <do_resolve+0xe5>
mov    $0x1,%edi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
mov    -0x10(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   10c0 <build_socks4a_resolve_request@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    12e4 <do_resolve+0x124>
mov    $0x1,%edi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     135d <do_resolve+0x19d>
mov    -0x24(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    133c <do_resolve+0x17c>
mov    $0x1,%edi
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
mov    -0x44(%rbp),%ecx
mov    -0x48(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    12ec <do_resolve+0x12c>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x48(%rbp)
cmpl   $0x8,-0x48(%rbp)
jge    13f7 <do_resolve+0x237>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
movslq -0x48(%rbp),%rax
add    %rax,%rsi
mov    $0x8,%edx
sub    -0x48(%rbp),%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    13c0 <do_resolve+0x200>
mov    $0x1,%edi
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
cmpl   $0x0,-0x44(%rbp)
jge    13e9 <do_resolve+0x229>
mov    $0x1,%edi
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
mov    -0x44(%rbp),%eax
add    -0x48(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    136d <do_resolve+0x1ad>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x8,%esi
call   10b0 <parse_socks4a_resolve_response@plt>
cmp    $0x0,%rax
jge    143a <do_resolve+0x27a>
mov    $0x1,%edi
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1454 <do_resolve+0x294>
mov    $0x2,%edi
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   10a0 <show_msg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_resolve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xe1f(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   10a0 <show_msg@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     126e <do_resolve+0xae>
mov    %eax,%r13d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    %r15d,%edi
call   1070 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
je     1297 <do_resolve+0xd7>
lea    0xdd3(%rip),%rsi
jmp    1275 <do_resolve+0xb5>
lea    0xda5(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <show_msg@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe51(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   10c0 <build_socks4a_resolve_request@plt>
test   %eax,%eax
js     1352 <do_resolve+0x192>
mov    0x8(%rsp),%rbx
je     12e6 <do_resolve+0x126>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     135e <do_resolve+0x19e>
movslq %eax,%rcx
add    %rcx,%rbx
sub    %eax,%ebp
jne    12c0 <do_resolve+0x100>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x20,%rsi
mov    $0x8,%edx
sub    %eax,%edx
mov    %r13d,%edi
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
je     1380 <do_resolve+0x1c0>
js     138c <do_resolve+0x1cc>
add    %eax,%ebx
cmp    $0x7,%ebx
jle    12f0 <do_resolve+0x130>
mov    %r13d,%edi
call   1090 <close@plt>
lea    0x20(%rsp),%rdi
mov    $0x8,%esi
mov    %r14,%rdx
call   10b0 <parse_socks4a_resolve_response@plt>
test   %rax,%rax
js     1398 <do_resolve+0x1d8>
lea    0xe05(%rip),%rsi
xor    %ebx,%ebx
mov    $0x2,%edi
xor    %eax,%eax
call   10a0 <show_msg@plt>
jmp    1286 <do_resolve+0xc6>
lea    0xd14(%rip),%rsi
jmp    1275 <do_resolve+0xb5>
lea    0xd34(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   10a0 <show_msg@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1281 <do_resolve+0xc1>
lea    0xd3b(%rip),%rsi
jmp    1275 <do_resolve+0xb5>
lea    0xd5d(%rip),%rsi
jmp    1275 <do_resolve+0xb5>
lea    0xd7b(%rip),%rsi
jmp    1275 <do_resolve+0xb5>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"do_resolve: resolving %s\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [37 x i8] c"do_resolve: problem creating socket\0A\00"
@AF_INET = global i32 0
@.str.2 = [46 x i8] c"do_resolve: error connecting to SOCKS server\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [44 x i8] c"do_resolve: error generating SOCKS request\0A\00"
@.str.5 = [41 x i8] c"do_resolve: error sending SOCKS request\0A\00"
@.str.6 = [46 x i8] c"do_resolve: EOF while reading SOCKS response\0A\00"
@.str.7 = [42 x i8] c"do_resolve: error reading SOCKS response\0A\00"
@.str.8 = [42 x i8] c"do_resolve: error parsing SOCKS response\0A\00"
@.str.9 = [21 x i8] c"do_resolve: success\0A\00"
define i32 @do_resolve(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [8 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%17 = load i8*, i8** %6
%18 = call i32 (i32, i8*, ...) @show_msg(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = load i32, i32* @IPPROTO_TCP
%22 = call i32 @socket(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %115
27: ; preds = %4
%28 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* %8
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* %7
%35 = call i32 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i32, i32* %10
%39 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%40 = call i64 @connect(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %27
%43 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %115
44: ; preds = %27
%45 = load i8*, i8** %6
%46 = call i32 @build_socks4a_resolve_request(i8** %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* %45)
store i32 %46, i32* %15
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %115
50: ; preds = %44
%51 = load i8*, i8** %12
store i8* %51, i8** %13
br label %52
52: ; preds = %67, %50
%53 = load i32, i32* %15
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %75
55: ; preds = %52
%56 = load i32, i32* %10
%57 = load i8*, i8** %13
%58 = load i32, i32* %15
%59 = call i64 @send(i32 %56, i8* %57, i32 %58, i32 0)
%60 = trunc i64 %59 to i32
store i32 %60, i32* %14
%61 = load i32, i32* %14
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %55
%64 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%65 = load i8*, i8** %12
%66 = call i32 @free(i8* %65)
store i32 -1, i32* %5
br label %115
67: ; preds = %55
%68 = load i32, i32* %14
%69 = load i32, i32* %15
%70 = sub nsw i32 %69, %68
store i32 %70, i32* %15
%71 = load i32, i32* %14
%72 = load i8*, i8** %13
%73 = sext i32 %71 to i64
%74 = getelementptr inbounds i8, i8* %72, i64 %73
store i8* %74, i8** %13
br label %52
75: ; preds = %52
%76 = load i8*, i8** %12
%77 = call i32 @free(i8* %76)
store i32 0, i32* %15
br label %78
78: ; preds = %100, %75
%79 = load i32, i32* %15
%80 = icmp slt i32 %79, 8
br i1 %80, label %81, label %104
81: ; preds = %78
%82 = load i32, i32* %10
%83 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%84 = load i32, i32* %15
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i32, i32* %15
%88 = sub nsw i32 8, %87
%89 = call i64 @recv(i32 %82, i8* %86, i32 %88, i32 0)
%90 = trunc i64 %89 to i32
store i32 %90, i32* %14
%91 = load i32, i32* %14
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %81
%94 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %5
br label %115
95: ; preds = %81
%96 = load i32, i32* %14
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %5
br label %115
100: ; preds = %95
%101 = load i32, i32* %14
%102 = load i32, i32* %15
%103 = add nsw i32 %102, %101
store i32 %103, i32* %15
br label %78
104: ; preds = %78
%105 = load i32, i32* %10
%106 = call i32 @close(i32 %105)
%107 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%108 = load i32*, i32** %9
%109 = call i64 @parse_socks4a_resolve_response(i8* %107, i32 8, i32* %108)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %104
%112 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %5
br label %115
113: ; preds = %104
%114 = call i32 (i32, i8*, ...) @show_msg(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %5
br label %115
115: ; preds = %113, %111, %98, %93, %63, %48, %42, %25
%116 = load i32, i32* %5
ret i32 %116
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"do_resolve: resolving %s\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [37 x i8] c"do_resolve: problem creating socket\0A\00"
@AF_INET = global i32 0
@.str.2 = [46 x i8] c"do_resolve: error connecting to SOCKS server\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [44 x i8] c"do_resolve: error generating SOCKS request\0A\00"
@.str.5 = [41 x i8] c"do_resolve: error sending SOCKS request\0A\00"
@.str.6 = [46 x i8] c"do_resolve: EOF while reading SOCKS response\0A\00"
@.str.7 = [42 x i8] c"do_resolve: error reading SOCKS response\0A\00"
@.str.8 = [42 x i8] c"do_resolve: error parsing SOCKS response\0A\00"
@.str.9 = [21 x i8] c"do_resolve: success\0A\00"
define i32 @do_resolve(i8* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca i8*
%7 = alloca [8 x i8]
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = bitcast i8** %6 to i8*
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%11 = tail call i32 (i32, i8*, ...) @show_msg(i32 2, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = load i32, i32* @IPPROTO_TCP
%15 = tail call i32 @socket(i32 %12, i32 %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = tail call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %86
19: ; preds = %4
%20 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 %2)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %23, i32* %24
%25 = call i32 @htonl(i32 %1)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%28 = call i64 @connect(i32 %15, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %19
%31 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %86
32: ; preds = %19
%33 = call i32 @build_socks4a_resolve_request(i8** %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
br label %86
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = icmp eq i32 %33, 0
br i1 %39, label %58, label %40
40: ; preds = %37, %50
%41 = phi i32 [ %51, %50 ], [ %33, %37 ]
%42 = phi i8* [ %54, %50 ], [ %38, %37 ]
%43 = call i64 @send(i32 %15, i8* %42, i32 %41, i32 0)
%44 = trunc i64 %43 to i32
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%48 = load i8*, i8** %6
%49 = call i32 @free(i8* %48)
br label %86
50: ; preds = %40
%51 = sub nsw i32 %41, %44
%52 = shl i64 %43, 32
%53 = ashr exact i64 %52, 32
%54 = getelementptr inbounds i8, i8* %42, i64 %53
%55 = icmp eq i32 %51, 0
br i1 %55, label %56, label %40
56: ; preds = %50
%57 = load i8*, i8** %6
br label %58
58: ; preds = %56, %37
%59 = phi i8* [ %57, %56 ], [ %38, %37 ]
%60 = call i32 @free(i8* %59)
br label %63
61: ; preds = %73
%62 = icmp slt i32 %75, 8
br i1 %62, label %63, label %78
63: ; preds = %58, %61
%64 = phi i32 [ 0, %58 ], [ %75, %61 ]
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %65
%67 = sub nsw i32 8, %64
%68 = call i64 @recv(i32 %15, i8* %66, i32 %67, i32 0)
%69 = trunc i64 %68 to i32
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %63
%72 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
br label %86
73: ; preds = %63
%74 = icmp slt i32 %69, 0
%75 = add nsw i32 %64, %69
br i1 %74, label %76, label %61
76: ; preds = %73
%77 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
br label %86
78: ; preds = %61
%79 = call i32 @close(i32 %15)
%80 = call i64 @parse_socks4a_resolve_response(i8* %10, i32 8, i32* %3)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %78
%83 = call i32 (i32, i8*, ...) @show_msg(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
br label %86
84: ; preds = %78
%85 = call i32 (i32, i8*, ...) @show_msg(i32 2, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
br label %86
86: ; preds = %84, %82, %76, %71, %46, %35, %30, %17
%87 = phi i32 [ -1, %17 ], [ -1, %30 ], [ -1, %35 ], [ -1, %46 ], [ -1, %71 ], [ -1, %76 ], [ -1, %82 ], [ 0, %84 ]
ret i32 %87
}