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

/* Variables and functions */
int /*<<< orphan*/ fwrite(char *, int, scalar_t__, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
int get_home_page(int socket_fd) {
  char buffer[10000];
  ssize_t number_characters_read;
  sprintf(buffer, "GET /\n");
  write(socket_fd, buffer, sizeof(buffer));
  while (1) {
    number_characters_read = read(socket_fd, buffer, 10000);
    if (number_characters_read == 0) {
      return 1;
    }
    fwrite(buffer, sizeof(char), number_characters_read, stdout);
  }
}


x86 assembly (clang, -O0):
<get_home_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x2720(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2710,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2710,%edx
call   1040 <read@plt>
mov    %rax,-0x2728(%rbp)
cmpq   $0x0,-0x2728(%rbp)
jne    11ac <get_home_page+0x6c>
mov    $0x1,%eax
add    $0x2730,%rsp
pop    %rbp
ret
lea    -0x2720(%rbp),%rdi
mov    -0x2728(%rbp),%rdx
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    1175 <get_home_page+0x35>

x86 assembly (clang, -O2):
<get_home_page>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2710,%rsp
mov    %edi,%ebp
movl   $0xa2f20,0x3(%rsp)
movl   $0x20544547,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1040 <read@plt>
test   %rax,%rax
je     11a7 <get_home_page+0x77>
mov    0x2e69(%rip),%r14
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1050 <fwrite@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1040 <read@plt>
test   %rax,%rax
jne    1180 <get_home_page+0x50>
mov    $0x1,%eax
add    $0x2710,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"GET /\0A\00"
@stdout = global i32 0
define i32 @get_home_page(i32 %0) {
%2 = alloca i32
%3 = alloca [10000 x i8]
%4 = alloca i64
store i32 %0, i32* %2
%5 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%9 = call i32 @write(i32 %7, i8* %8, i32 10000)
br label %10
10: ; preds = %1, %17
%11 = load i32, i32* %2
%12 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 10000)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
ret i32 1
17: ; preds = %10
%18 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%19 = load i64, i64* %4
%20 = load i32, i32* @stdout
%21 = call i32 @fwrite(i8* %18, i32 1, i64 %19, i32 %20)
br label %10
}

LLVM IR (-O2):
@.str = [7 x i8] c"GET /\0A\00"
@stdout = global i32 0
define i32 @get_home_page(i32 %0) {
%2 = alloca [10000 x i8]
%3 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%4 = call i32 @write(i32 %0, i8* %3, i32 10000)
%5 = call i64 @read(i32 %0, i8* %3, i32 10000)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %1
ret i32 1
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ %5, %1 ]
%10 = load i32, i32* @stdout
%11 = call i32 @fwrite(i8* %3, i32 1, i64 %9, i32 %10)
%12 = call i64 @read(i32 %0, i8* %3, i32 10000)
%13 = icmp eq i64 %12, 0
br i1 %13, label %7, label %8
}