#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 client_init(char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, ...);
char *strchr(char *, char);
int process_request(char *buffer) {
  int port, c;
  char *aux;
  char ip[1024];
  sscanf(buffer, "GET http://%s/", ip);
  if ((aux = strchr(ip, ':'))) {
    *aux = 0;
    sscanf(aux + 1, "%d", &port);
  } else
    port = 80;
  printf("Request to connect to: %s(%d)\n", ip, port);
  c = client_init(ip, port);
  return c;
}


x86 assembly (clang, -O0):
<process_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ad <process_request+0x6d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
lea    0xe72(%rip),%rsi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
jmp    11b4 <process_request+0x74>
movl   $0x50,-0xc(%rbp)
lea    -0x420(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <client_init@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_request>:
push   %rbx
sub    $0x410,%rsp
lea    0xeb1(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1193 <process_request+0x53>
movb   $0x0,(%rax)
add    $0x1,%rax
lea    0xe91(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0xc(%rsp),%edx
jmp    11a0 <process_request+0x60>
movl   $0x50,0xc(%rsp)
mov    $0x50,%edx
lea    0xe6b(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1060 <client_init@plt>
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"GET http://%s/\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"Request to connect to: %s(%d)\0A\00"
define i32 @process_request(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = call i32 (i8*, i8*, ...) @sscanf(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i8* @strchr(i8* %10, i8 signext 58)
store i8* %11, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i8*, i8** %5
store i8 0, i8* %14
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i32 (i8*, i8*, ...) @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %19
18: ; preds = %1
store i32 80, i32* %3
br label %19
19: ; preds = %18, %13
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32 %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @client_init(i8* %23, i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [15 x i8] c"GET http://%s/\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [31 x i8] c"Request to connect to: %s(%d)\0A\00"
define i32 @process_request(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, i8*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i8* @strchr(i8* %5, i8 signext 58)
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
store i8 0, i8* %7
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
br label %14
13: ; preds = %1
store i32 80, i32* %2
br label %14
14: ; preds = %13, %9
%15 = phi i32 [ 80, %13 ], [ %12, %9 ]
%16 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @client_init(i8* %5, i32 %17)
ret i32 %18
}