#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int getHostname_AND_portnum(char *req_message, char *hostname) {
  char temp[2048];
  char *token;
  int portnumber = 80;
  int i = 0;
  strcpy(temp, req_message);
  token = strtok(temp, " \n");
  while (token != NULL) {
    token = strtok(NULL, " \n");
    if (strcmp(token, "Host:") == 0) {
      token = strtok(NULL, " \n");
      break;
    }
  }
  if (token == NULL) {
    printf("Server : request message error\n");
    exit(0);
  }
  token[strlen(token) - 1] = '\0';
  strcpy(hostname, token);
  i = strlen(hostname) - 1;
  if (hostname[i] == ':') {
    portnumber = atoi(&hostname[i + 1]);
    hostname[i] = '\0';
  }
  return portnumber;
}


x86 assembly (clang, -O0):
<getHostname_AND_portnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x50,-0x81c(%rbp)
movl   $0x0,-0x820(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x810(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
je     1224 <getHostname_AND_portnum+0xb4>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe26(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <getHostname_AND_portnum+0xaf>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf2(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x818(%rbp)
jmp    1224 <getHostname_AND_portnum+0xb4>
jmp    11c1 <getHostname_AND_portnum+0x51>
cmpq   $0x0,-0x818(%rbp)
jne    1245 <getHostname_AND_portnum+0xd5>
lea    0xdd0(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x818(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    -0x818(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x828(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x818(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x820(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x820(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    12d8 <getHostname_AND_portnum+0x168>
mov    -0x10(%rbp),%rdi
mov    -0x820(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x81c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x820(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x81c(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHostname_AND_portnum>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xe6a(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
lea    0xe58(%rip),%r12
nopl   0x0(%rax,%rax,1)
test   %rbx,%rbx
je     123c <getHostname_AND_portnum+0xcc>
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b0 <getHostname_AND_portnum+0x40>
lea    0xe23(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
test   %rax,%rax
je     123c <getHostname_AND_portnum+0xcc>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
mov    $0x50,%eax
cmpb   $0x3a,-0x1(%rbx,%r14,1)
jne    122d <getHostname_AND_portnum+0xbd>
lea    (%r14,%rbx,1),%rdi
call   1080 <atoi@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdc6(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c" \0A\00"
@.str.1 = [6 x i8] c"Host:\00"
@.str.2 = [32 x i8] c"Server : request message error\0A\00"
define i32 @getHostname_AND_portnum(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2048 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 80, i32* %7
store i32 0, i32* %8
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
br label %14
14: ; preds = %24, %2
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %23, i8** %6
br label %25
24: ; preds = %17
br label %14
25: ; preds = %22, %14
%26 = load i8*, i8** %6
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %25
%32 = load i8*, i8** %6
%33 = load i8*, i8** %6
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %32, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %4
%39 = load i8*, i8** %6
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %4
%42 = call i32 @strlen(i8* %41)
%43 = sub nsw i32 %42, 1
store i32 %43, i32* %8
%44 = load i8*, i8** %4
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 58
br i1 %50, label %51, label %62
51: ; preds = %31
%52 = load i8*, i8** %4
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %7
%58 = load i8*, i8** %4
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 0, i8* %61
br label %62
62: ; preds = %51, %31
%63 = load i32, i32* %7
ret i32 %63
}

LLVM IR (-O2):
@.str = [3 x i8] c" \0A\00"
@.str.1 = [6 x i8] c"Host:\00"
@str = [31 x i8] c"Server : request message error\00"
define i32 @getHostname_AND_portnum(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %10, %2
%8 = phi i8* [ %6, %2 ], [ %11, %10 ]
%9 = icmp eq i8* %8, null
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %10
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %7, %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %14
%21 = call i32 @strlen(i8* %15)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %15, i64 %23
store i8 0, i8* %24
%25 = call i32 @strcpy(i8* %1, i8* %15)
%26 = call i32 @strlen(i8* %1)
%27 = add nsw i32 %26, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %1, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 58
br i1 %31, label %32, label %36
32: ; preds = %20
%33 = sext i32 %26 to i64
%34 = getelementptr inbounds i8, i8* %1, i64 %33
%35 = call i32 @atoi(i8* %34)
store i8 0, i8* %29
br label %36
36: ; preds = %32, %20
%37 = phi i32 [ %35, %32 ], [ 80, %20 ]
ret i32 %37
}