#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ write(int, char *, int);
void test_request(int sockfd, char *path, char *file) {
  char file_path[1000];
  static char buffer[100000];
  int offset = 0;
  sprintf(file_path, "%s%s", path, file);
  printf("Teste : %s\n", file_path);
  int fd = open(file_path, O_RDONLY);
  int l = read(fd, buffer, sizeof(buffer));
  close(fd);
  write(sockfd, buffer, l);
  printf("written : %d\n", l);
  memset(buffer, 0, sizeof(buffer));
  return;
  offset = 0;
  int header = 0;
  while (1) {
    int ret = read(sockfd, &buffer[offset], 1);
    if (ret <= 0)
      break;
    printf("%s", buffer);
    offset += ret;
    if ((buffer[0] == '\r') && (buffer[1] == '\n')) {
      break;
    }
    if ((buffer[offset - 2] == '\r') && (buffer[offset - 1] == '\n')) {
      buffer[offset] = 0;
      printf("%s", buffer);
      offset = 0;
    }
  }
}


x86 assembly (clang, -O0):
<test_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x404(%rbp)
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe5a(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x400(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x400(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x408(%rbp)
mov    -0x408(%rbp),%edi
lea    0x2e88(%rip),%rsi
mov    $0x186a0,%edx
call   1070 <read@plt>
mov    %eax,-0x40c(%rbp)
mov    -0x408(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
mov    -0x40c(%rbp),%edx
lea    0x2e5d(%rip),%rsi
call   1030 <write@plt>
mov    -0x40c(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x2e3d(%rip),%rdi
xor    %esi,%esi
mov    $0x186a0,%edx
call   1050 <memset@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_request>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %edi,%r14d
lea    0xe73(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0x2ead(%rip),%r15
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x186a0,%edx
call   1070 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
lea    0xe22(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x186a0,%edx
call   1050 <memset@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@test_request.buffer = internal global [100000 x i8] zeroinitializer
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [12 x i8] c"Teste : %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"written : %d\0A\00"
define void @test_request(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1000 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %8
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = call i32 @read(i32 %21, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @test_request.buffer, i64 0, i64 0), i32 100000)
store i32 %22, i32* %10
%23 = load i32, i32* %9
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %4
%26 = load i32, i32* %10
%27 = call i32 @write(i32 %25, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @test_request.buffer, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %10
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @memset(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @test_request.buffer, i64 0, i64 0), i32 0, i32 100000)
ret void
}

LLVM IR (-O2):
@test_request.buffer = internal global [100000 x i8] zeroinitializer
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [12 x i8] c"Teste : %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"written : %d\0A\00"
define void @test_request(i32 %0, i8* %1, i8* %2) {
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %5, i32 %8)
%10 = call i32 @read(i32 %9, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @test_request.buffer, i64 0, i64 0), i32 100000)
%11 = call i32 @close(i32 %9)
%12 = call i32 @write(i32 %0, i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @test_request.buffer, i64 0, i64 0), i32 %10)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%14 = call i32 @memset(i8* getelementptr inbounds ([100000 x i8], [100000 x i8]* @test_request.buffer, i64 0, i64 0), i32 0, i32 100000)
ret void
}