#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 */
scalar_t__ cache_check(char *, int);
int /*<<< orphan*/ client(char *, char *, int, char *);
char *get_URL_from_request(char *);
char *get_host_from_request(char *);
char *host_to_ipaddr(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int parse_request(char *msg, int sock) {
  printf(" *** INCOMING REQUEST ***\n");
  char *msg_whole;
  msg_whole = malloc((1024 * 16));
  strcpy(msg_whole, msg);
  char *URL = get_URL_from_request(msg);
  char *host = get_host_from_request(msg);
  printf("FINAL URL: %s\nFINAL HOST: %s\n", URL, host);
  char *ip_addr = host_to_ipaddr(host);
  if (ip_addr == NULL)
    return 1;
  if (cache_check(URL, sock))
    return 0;
  client(ip_addr, msg_whole, sock, URL);
  return 0;
}


x86 assembly (clang, -O0):
<parse_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <get_URL_from_request@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <get_host_from_request@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1070 <host_to_ipaddr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    120c <parse_request+0x8c>
movl   $0x1,-0x4(%rbp)
jmp    1249 <parse_request+0xc9>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <cache_check@plt>
cmp    $0x0,%rax
je     122e <parse_request+0xae>
movl   $0x0,-0x4(%rbp)
jmp    1249 <parse_request+0xc9>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1090 <client@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4000,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1060 <get_URL_from_request@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1090 <get_host_from_request@plt>
mov    %rax,%rbp
lea    0xe21(%rip),%rdi
xor    %r12d,%r12d
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1080 <host_to_ipaddr@plt>
test   %rax,%rax
je     1222 <parse_request+0x92>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r14d,%esi
call   10b0 <cache_check@plt>
test   %rax,%rax
jne    1228 <parse_request+0x98>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %rbx,%rcx
call   10a0 <client@plt>
jmp    1228 <parse_request+0x98>
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c" *** INCOMING REQUEST ***\0A\00"
@.str.1 = [30 x i8] c"FINAL URL: %s\0AFINAL HOST: %s\0A\00"
define i32 @parse_request(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i8* @malloc(i32 16384)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %4
%16 = call i8* @get_URL_from_request(i8* %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %4
%18 = call i8* @get_host_from_request(i8* %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %7
%20 = load i8*, i8** %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i8*, i8** %8
%23 = call i8* @host_to_ipaddr(i8* %22)
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %2
store i32 1, i32* %3
br label %39
27: ; preds = %2
%28 = load i8*, i8** %7
%29 = load i32, i32* %5
%30 = call i64 @cache_check(i8* %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %3
br label %39
33: ; preds = %27
%34 = load i8*, i8** %9
%35 = load i8*, i8** %6
%36 = load i32, i32* %5
%37 = load i8*, i8** %7
%38 = call i32 @client(i8* %34, i8* %35, i32 %36, i8* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %33, %32, %26
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"FINAL URL: %s\0AFINAL HOST: %s\0A\00"
@str = [26 x i8] c" *** INCOMING REQUEST ***\00"
define i32 @parse_request(i8* %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%4 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i8* @get_URL_from_request(i8* %0)
%7 = tail call i8* @get_host_from_request(i8* %0)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %7)
%9 = tail call i8* @host_to_ipaddr(i8* %7)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = tail call i64 @cache_check(i8* %6, i32 %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @client(i8* %9, i8* %4, i32 %1, i8* %6)
br label %16
16: ; preds = %11, %2, %14
%17 = phi i32 [ 0, %14 ], [ 1, %2 ], [ 0, %11 ]
ret i32 %17
}