#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);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strpbrk(char *, char *);
int find_target_address(char *uri, char *target_address, char *path,
                        int *port) {
  if (strncasecmp(uri, "http://", 7) == 0) {
    char *hostbegin, *hostend, *pathbegin;
    int len;
    hostbegin = uri + 7;
    hostend = strpbrk(hostbegin, " :/\r\n");
    if (hostend == NULL) {
      hostend = hostbegin + strlen(hostbegin);
    }
    len = hostend - hostbegin;
    strncpy(target_address, hostbegin, len);
    target_address[len] = '\0';
    if (*hostend == ':')
      *port = atoi(hostend + 1);
    pathbegin = strchr(hostbegin, '/');
    if (pathbegin == NULL) {
      path[0] = '\0';
    } else {
      strcpy(path, pathbegin);
    }
    return 0;
  }
  target_address[0] = '\0';
  return -1;
}


x86 assembly (clang, -O0):
<find_target_address>:
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    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x7,%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1284 <find_target_address+0x114>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <strpbrk@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11f3 <find_target_address+0x83>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1242 <find_target_address+0xd2>
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1090 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    126b <find_target_address+0xfb>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1278 <find_target_address+0x108>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    1292 <find_target_address+0x122>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_target_address>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xe72(%rip),%rsi
mov    $0x7,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
je     11a9 <find_target_address+0x39>
movb   $0x0,(%r12)
mov    $0xffffffff,%eax
jmp    1228 <find_target_address+0xb8>
add    $0x7,%rbx
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strpbrk@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11d2 <find_target_address+0x62>
mov    %rbx,%rdi
call   1050 <strlen@plt>
movslq %eax,%r13
add    %rbx,%r13
mov    %r13,%rbp
sub    %rbx,%rbp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r12,%rax,1)
cmpb   $0x3a,0x0(%r13)
jne    1203 <find_target_address+0x93>
add    $0x1,%r13
mov    %r13,%rdi
call   1090 <atoi@plt>
mov    %eax,(%r15)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1222 <find_target_address+0xb2>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
jmp    1226 <find_target_address+0xb6>
movb   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [6 x i8] c" :/\0D\0A\00"
define i32 @find_target_address(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
%14 = load i8*, i8** %6
%15 = call i64 @strncasecmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %67
17: ; preds = %4
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 7
store i8* %19, i8** %10
%20 = load i8*, i8** %10
%21 = call i8* @strpbrk(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i8*, i8** %10
%26 = load i8*, i8** %10
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8* %29, i8** %11
br label %30
30: ; preds = %24, %17
%31 = load i8*, i8** %11
%32 = load i8*, i8** %10
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %13
%37 = load i8*, i8** %7
%38 = load i8*, i8** %10
%39 = load i32, i32* %13
%40 = call i32 @strncpy(i8* %37, i8* %38, i32 %39)
%41 = load i8*, i8** %7
%42 = load i32, i32* %13
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %11
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 58
br i1 %48, label %49, label %54
49: ; preds = %30
%50 = load i8*, i8** %11
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = call i32 @atoi(i8* %51)
%53 = load i32*, i32** %9
store i32 %52, i32* %53
br label %54
54: ; preds = %49, %30
%55 = load i8*, i8** %10
%56 = call i8* @strchr(i8* %55, i8 signext 47)
store i8* %56, i8** %12
%57 = load i8*, i8** %12
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %54
%60 = load i8*, i8** %8
%61 = getelementptr inbounds i8, i8* %60, i64 0
store i8 0, i8* %61
br label %66
62: ; preds = %54
%63 = load i8*, i8** %8
%64 = load i8*, i8** %12
%65 = call i32 @strcpy(i8* %63, i8* %64)
br label %66
66: ; preds = %62, %59
store i32 0, i32* %5
br label %70
67: ; preds = %4
%68 = load i8*, i8** %7
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 0, i8* %69
store i32 -1, i32* %5
br label %70
70: ; preds = %67, %66
%71 = load i32, i32* %5
ret i32 %71
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [6 x i8] c" :/\0D\0A\00"
define i32 @find_target_address(i8* %0, i8* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %36
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 7
%9 = tail call i8* @strpbrk(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 @strlen(i8* %8)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
br label %15
15: ; preds = %11, %7
%16 = phi i8* [ %14, %11 ], [ %9, %7 ]
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint i8* %8 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = tail call i32 @strncpy(i8* %1, i8* %8, i32 %20)
%22 = shl i64 %19, 32
%23 = ashr exact i64 %22, 32
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 0, i8* %24
%25 = load i8, i8* %16
%26 = icmp eq i8 %25, 58
br i1 %26, label %27, label %30
27: ; preds = %15
%28 = getelementptr inbounds i8, i8* %16, i64 1
%29 = tail call i32 @atoi(i8* %28)
store i32 %29, i32* %3
br label %30
30: ; preds = %27, %15
%31 = tail call i8* @strchr(i8* %8, i8 signext 47)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %34
33: ; preds = %30
store i8 0, i8* %2
br label %37
34: ; preds = %30
%35 = tail call i32 @strcpy(i8* %2, i8* %31)
br label %37
36: ; preds = %4
store i8 0, i8* %1
br label %37
37: ; preds = %33, %34, %36
%38 = phi i32 [ -1, %36 ], [ 0, %34 ], [ 0, %33 ]
ret i32 %38
}