#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 atoi(char *);
char *strchr(char *, char);
char *strdup(char *);
void proxy_to_host_and_port(char *in, char **proxy_host, int *proxy_port) {
  if (in[0] == '[') {
    char *dummy = NULL;
    *proxy_host = strdup(in + 1);
    dummy = strchr(*proxy_host, ']');
    if (dummy) {
      *dummy = 0x00;
      *proxy_port = atoi(dummy + 2);
    }
  } else {
    char *dummy = strchr(in, ':');
    *proxy_host = in;
    if (dummy) {
      *dummy = 0x00;
      *proxy_port = atoi(dummy + 1);
    }
  }
}


x86 assembly (clang, -O0):
<proxy_to_host_and_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    11b4 <proxy_to_host_and_port+0x84>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11af <proxy_to_host_and_port+0x7f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x2,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11fd <proxy_to_host_and_port+0xcd>
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     11f8 <proxy_to_host_and_port+0xc8>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11fd <proxy_to_host_and_port+0xcd>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proxy_to_host_and_port>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
cmpb   $0x5b,(%rdi)
jne    116d <proxy_to_host_and_port+0x3d>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    $0x5d,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1194 <proxy_to_host_and_port+0x64>
movb   $0x0,(%rax)
add    $0x2,%rax
jmp    1189 <proxy_to_host_and_port+0x59>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rbx,(%r15)
test   %rax,%rax
je     1194 <proxy_to_host_and_port+0x64>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @proxy_to_host_and_port(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 91
br i1 %13, label %14, label %31
14: ; preds = %3
store i8* null, i8** %7
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i8* @strdup(i8* %16)
%18 = load i8**, i8*** %5
store i8* %17, i8** %18
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = call i8* @strchr(i8* %20, i8 signext 93)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %14
%25 = load i8*, i8** %7
store i8 0, i8* %25
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 2
%28 = call i32 @atoi(i8* %27)
%29 = load i32*, i32** %6
store i32 %28, i32* %29
br label %30
30: ; preds = %24, %14
br label %45
31: ; preds = %3
%32 = load i8*, i8** %4
%33 = call i8* @strchr(i8* %32, i8 signext 58)
store i8* %33, i8** %8
%34 = load i8*, i8** %4
%35 = load i8**, i8*** %5
store i8* %34, i8** %35
%36 = load i8*, i8** %8
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i8*, i8** %8
store i8 0, i8* %39
%40 = load i8*, i8** %8
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @atoi(i8* %41)
%43 = load i32*, i32** %6
store i32 %42, i32* %43
br label %44
44: ; preds = %38, %31
br label %45
45: ; preds = %44, %30
ret void
}

LLVM IR (-O2):
define void @proxy_to_host_and_port(i8* %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 91
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = tail call i8* @strdup(i8* %7)
store i8* %8, i8** %1
%9 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 93)
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %6
store i8 0, i8* %9
%12 = getelementptr inbounds i8, i8* %9, i64 2
br label %18
13: ; preds = %3
%14 = tail call i8* @strchr(i8* %0, i8 signext 58)
store i8* %0, i8** %1
%15 = icmp eq i8* %14, null
br i1 %15, label %21, label %16
16: ; preds = %13
store i8 0, i8* %14
%17 = getelementptr inbounds i8, i8* %14, i64 1
br label %18
18: ; preds = %11, %16
%19 = phi i8* [ %17, %16 ], [ %12, %11 ]
%20 = tail call i32 @atoi(i8* %19)
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %13, %6
ret void
}