#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 *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strncmp(char *, char *, int);
int parse_proxy_param(char *proxy_spec, char **proxy_host, int *proxy_port,
                      char **proxy_user, char **proxy_password) {
  char *login_sep, *colon_sep, *trailer_sep;
  if (!strncmp("http://", proxy_spec, 7)) {
    proxy_spec += 7;
  }
  login_sep = strchr(proxy_spec, '@');
  if (!login_sep) {
    colon_sep = strchr(proxy_spec, ':');
    if (!colon_sep || (colon_sep > login_sep)) {
      fprintf(stderr, "Expected password in '%s'\n", proxy_spec);
      return 1;
    }
    *colon_sep = '\0';
    *proxy_user = proxy_spec;
    *login_sep = '\0';
    *proxy_password = colon_sep + 1;
    proxy_spec = login_sep + 1;
  }
  trailer_sep = strchr(proxy_spec, '/');
  if (trailer_sep) {
    *trailer_sep = '\0';
  }
  colon_sep = strchr(proxy_spec, ':');
  if (colon_sep) {
    *colon_sep = '\0';
    *proxy_host = proxy_spec;
    *proxy_port = atoi(colon_sep + 1);
    if (*proxy_port == 0) {
      return 2;
    }
  } else {
    *proxy_port = 80;
    *proxy_host = proxy_spec;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_proxy_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe99(%rip),%rdi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1186 <parse_proxy_param+0x46>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1227 <parse_proxy_param+0xe7>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11ce <parse_proxy_param+0x8e>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jbe    11f3 <parse_proxy_param+0xb3>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe26(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c9 <parse_proxy_param+0x189>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rcx
add    $0x1,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     124b <parse_proxy_param+0x10b>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12ad <parse_proxy_param+0x16d>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    12a8 <parse_proxy_param+0x168>
movl   $0x2,-0x4(%rbp)
jmp    12c9 <parse_proxy_param+0x189>
jmp    12c2 <parse_proxy_param+0x182>
mov    -0x20(%rbp),%rax
movl   $0x50,(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_proxy_param>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xea8(%rip),%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
lea    0x7(%rbx),%r12
test   %eax,%eax
cmovne %rbx,%r12
mov    %r12,%rdi
mov    $0x40,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c8 <parse_proxy_param+0x88>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1196 <parse_proxy_param+0x56>
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11e7 <parse_proxy_param+0xa7>
movb   $0x0,(%rax)
mov    %r12,(%r15)
add    $0x1,%rax
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,(%r14)
test   %eax,%eax
jne    11f1 <parse_proxy_param+0xb1>
mov    $0x2,%eax
jmp    11f3 <parse_proxy_param+0xb3>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11f3 <parse_proxy_param+0xb3>
movl   $0x50,(%r14)
mov    %r12,(%r15)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Expected password in '%s'\0A\00"
define i32 @parse_proxy_param(i8* %0, i8** %1, i32* %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %7
store i8** %1, i8*** %8
store i32* %2, i32** %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
%15 = load i8*, i8** %7
%16 = call i32 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %15, i32 7)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %5
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 7
store i8* %20, i8** %7
br label %21
21: ; preds = %18, %5
%22 = load i8*, i8** %7
%23 = call i8* @strchr(i8* %22, i8 signext 64)
store i8* %23, i8** %12
%24 = load i8*, i8** %12
%25 = icmp ne i8* %24, null
br i1 %25, label %49, label %26
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = call i8* @strchr(i8* %27, i8 signext 58)
store i8* %28, i8** %13
%29 = load i8*, i8** %13
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i8*, i8** %13
%33 = load i8*, i8** %12
%34 = icmp ugt i8* %32, %33
br i1 %34, label %35, label %39
35: ; preds = %31, %26
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %7
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %37)
store i32 1, i32* %6
br label %79
39: ; preds = %31
%40 = load i8*, i8** %13
store i8 0, i8* %40
%41 = load i8*, i8** %7
%42 = load i8**, i8*** %10
store i8* %41, i8** %42
%43 = load i8*, i8** %12
store i8 0, i8* %43
%44 = load i8*, i8** %13
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8**, i8*** %11
store i8* %45, i8** %46
%47 = load i8*, i8** %12
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8* %48, i8** %7
br label %49
49: ; preds = %39, %21
%50 = load i8*, i8** %7
%51 = call i8* @strchr(i8* %50, i8 signext 47)
store i8* %51, i8** %14
%52 = load i8*, i8** %14
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = load i8*, i8** %14
store i8 0, i8* %55
br label %56
56: ; preds = %54, %49
%57 = load i8*, i8** %7
%58 = call i8* @strchr(i8* %57, i8 signext 58)
store i8* %58, i8** %13
%59 = load i8*, i8** %13
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %74
61: ; preds = %56
%62 = load i8*, i8** %13
store i8 0, i8* %62
%63 = load i8*, i8** %7
%64 = load i8**, i8*** %8
store i8* %63, i8** %64
%65 = load i8*, i8** %13
%66 = getelementptr inbounds i8, i8* %65, i64 1
%67 = call i32 @atoi(i8* %66)
%68 = load i32*, i32** %9
store i32 %67, i32* %68
%69 = load i32*, i32** %9
%70 = load i32, i32* %69
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %61
store i32 2, i32* %6
br label %79
73: ; preds = %61
br label %78
74: ; preds = %56
%75 = load i32*, i32** %9
store i32 80, i32* %75
%76 = load i8*, i8** %7
%77 = load i8**, i8*** %8
store i8* %76, i8** %77
br label %78
78: ; preds = %74, %73
store i32 0, i32* %6
br label %79
79: ; preds = %78, %72, %35
%80 = load i32, i32* %6
ret i32 %80
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Expected password in '%s'\0A\00"
define i32 @parse_proxy_param(i8* %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2, i8** nocapture readnone %3, i8** nocapture readnone %4) {
%6 = tail call i32 @strncmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i32 7)
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i64 7, i64 0
%9 = getelementptr i8, i8* %0, i64 %8
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 64)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %28
15: ; preds = %5
%16 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 47)
%17 = icmp eq i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15
store i8 0, i8* %16
br label %19
19: ; preds = %18, %15
%20 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 58)
%21 = icmp eq i8* %20, null
br i1 %21, label %26, label %22
22: ; preds = %19
store i8 0, i8* %20
store i8* %9, i8** %1
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = tail call i32 @atoi(i8* %23)
store i32 %24, i32* %2
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %27
26: ; preds = %19
store i32 80, i32* %2
store i8* %9, i8** %1
br label %27
27: ; preds = %22, %26
br label %28
28: ; preds = %22, %27, %12
%29 = phi i32 [ 0, %27 ], [ 1, %12 ], [ 2, %22 ]
ret i32 %29
}