#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 /*<<< orphan*/ logger(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ readMessage(int, char *);
int /*<<< orphan*/ sendFile(int, char *);
int sendPathToIndexProcess(char *);
scalar_t__ strcmp(char *, char *);
char *substring(char *, int, int);
void processHttpMessage(char *httpMessage, int sockClient) {
  printf("funcion processHttpMessage\n");
  printf("Full HTTP Message:\n");
  logger(httpMessage);
  char GET[4] = "GET\0";
  char *method = substring(httpMessage, 0, 3);
  logger("Method: ");
  logger(method);
  if (strcmp(method, GET) == 0) {
    int i = 0;
    while (httpMessage[i] != '\n') {
      i++;
    }
    char *path = substring(httpMessage, 5, i - 10);
    logger(path);
    int sockIndexProcess = sendPathToIndexProcess(path);
    char *realPath = malloc(8092);
    readMessage(sockIndexProcess, realPath);
    sendFile(sockClient, realPath);
  }
}


x86 assembly (clang, -O0):
<processHttpMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <logger@plt>
mov    0xe7a(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <substring@plt>
mov    %rax,-0x18(%rbp)
lea    0xe60(%rip),%rdi
call   1070 <logger@plt>
mov    -0x18(%rbp),%rdi
call   1070 <logger@plt>
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1276 <processHttpMessage+0xf6>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1223 <processHttpMessage+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1200 <processHttpMessage+0x80>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0xa,%edx
mov    $0x5,%esi
call   1040 <substring@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <logger@plt>
mov    -0x28(%rbp),%rdi
call   1090 <sendPathToIndexProcess@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x1f9c,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1060 <readMessage@plt>
mov    -0xc(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   10a0 <sendFile@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processHttpMessage>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <logger@plt>
movl   $0x544547,0xc(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1040 <substring@plt>
mov    %rax,%rbp
lea    0xe31(%rip),%rdi
call   1070 <logger@plt>
mov    %rbp,%rdi
call   1070 <logger@plt>
lea    0xc(%rsp),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1241 <processHttpMessage+0xc1>
xor    %edx,%edx
cmpb   $0xa,(%rbx,%rdx,1)
lea    0x1(%rdx),%rdx
jne    11f0 <processHttpMessage+0x70>
add    $0xfffffff5,%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <substring@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <logger@plt>
mov    %rbx,%rdi
call   1090 <sendPathToIndexProcess@plt>
mov    %eax,%ebx
mov    $0x1f9c,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %ebx,%edi
mov    %rax,%rsi
call   1060 <readMessage@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   10a0 <sendFile@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"funcion processHttpMessage\0A\00"
@.str.1 = [20 x i8] c"Full HTTP Message:\0A\00"
@__const.processHttpMessage.GET = [4 x i8] c"GET\00"
@.str.2 = [9 x i8] c"Method: \00"
define void @processHttpMessage(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8*, i8** %3
%14 = call i32 @logger(i8* %13)
%15 = bitcast [4 x i8]* %5 to i8*
%16 = load i8*, i8** %3
%17 = call i8* @substring(i8* %16, i32 0, i32 3)
store i8* %17, i8** %6
%18 = call i32 @logger(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%19 = load i8*, i8** %6
%20 = call i32 @logger(i8* %19)
%21 = load i8*, i8** %6
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %53
25: ; preds = %2
store i32 0, i32* %7
br label %26
26: ; preds = %34, %25
%27 = load i8*, i8** %3
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %26
37: ; preds = %26
%38 = load i8*, i8** %3
%39 = load i32, i32* %7
%40 = sub nsw i32 %39, 10
%41 = call i8* @substring(i8* %38, i32 5, i32 %40)
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = call i32 @logger(i8* %42)
%44 = load i8*, i8** %8
%45 = call i32 @sendPathToIndexProcess(i8* %44)
store i32 %45, i32* %9
%46 = call i8* @malloc(i32 8092)
store i8* %46, i8** %10
%47 = load i32, i32* %9
%48 = load i8*, i8** %10
%49 = call i32 @readMessage(i32 %47, i8* %48)
%50 = load i32, i32* %4
%51 = load i8*, i8** %10
%52 = call i32 @sendFile(i32 %50, i8* %51)
br label %53
53: ; preds = %37, %2
ret void
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"Method: \00"
@str = [27 x i8] c"funcion processHttpMessage\00"
@str.3 = [19 x i8] c"Full HTTP Message:\00"
define void @processHttpMessage(i8* %0, i32 %1) {
%3 = alloca i32
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
%6 = tail call i32 @logger(i8* %0)
%7 = bitcast i32* %3 to i8*
store i32 5522759, i32* %3
%8 = tail call i8* @substring(i8* %0, i32 0, i32 3)
%9 = tail call i32 @logger(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @logger(i8* %8)
%11 = call i64 @strcmp(i8* %8, i8* %7)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %2, %13
%14 = phi i64 [ %18, %13 ], [ 0, %2 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
%18 = add nuw i64 %14, 1
br i1 %17, label %19, label %13
19: ; preds = %13
%20 = trunc i64 %14 to i32
%21 = add nsw i32 %20, -10
%22 = call i8* @substring(i8* %0, i32 5, i32 %21)
%23 = call i32 @logger(i8* %22)
%24 = call i32 @sendPathToIndexProcess(i8* %22)
%25 = call dereferenceable_or_null(8092) i8* @malloc(i32 8092)
%26 = call i32 @readMessage(i32 %24, i8* %25)
%27 = call i32 @sendFile(i32 %1, i8* %25)
br label %28
28: ; preds = %19, %2
ret void
}