#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;

/* 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*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void get_home_page(int socket_fd) {
  char buffer[10000];
  ssize_t number_characters_read;
  sprintf(buffer, "GET /\n");
  write(socket_fd, buffer, strlen(buffer));
  while (1) {
    number_characters_read = read(socket_fd, buffer, 10000);
    if (number_characters_read == 0) {
      return;
    }
    fwrite(buffer, sizeof(char), number_characters_read, stdout);
  }
}


x86 assembly (clang, -O0):
<get_home_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x2720(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2734(%rbp)
lea    -0x2720(%rbp),%rax
mov    %rax,-0x2730(%rbp)
lea    -0x2720(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2734(%rbp),%edi
mov    -0x2730(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x2720(%rbp),%rsi
mov    $0x2710,%edx
call   1050 <read@plt>
mov    %rax,-0x2728(%rbp)
cmpq   $0x0,-0x2728(%rbp)
jne    11da <get_home_page+0x8a>
add    $0x2740,%rsp
pop    %rbp
ret
lea    -0x2720(%rbp),%rdi
mov    -0x2728(%rbp),%rdx
mov    0x2df1(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    11a8 <get_home_page+0x58>

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,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1050 <read@plt>
test   %rax,%rax
je     11c7 <get_home_page+0x87>
mov    0x2e52(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1060 <fwrite@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2710,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    11a0 <get_home_page+0x60>
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 void @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 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @write(i32 %7, i8* %8, i32 %10)
br label %12
12: ; preds = %1, %19
%13 = load i32, i32* %2
%14 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%15 = call i64 @read(i32 %13, i8* %14, i32 10000)
store i64 %15, i64* %4
%16 = load i64, i64* %4
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
ret void
19: ; preds = %12
%20 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%21 = load i64, i64* %4
%22 = load i32, i32* @stdout
%23 = call i32 @fwrite(i8* %20, i32 1, i64 %21, i32 %22)
br label %12
}

LLVM IR (-O2):
@.str = [7 x i8] c"GET /\0A\00"
@stdout = global i32 0
define void @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 @strlen(i8* %3)
%5 = call i32 @write(i32 %0, i8* %3, i32 %4)
%6 = call i64 @read(i32 %0, i8* %3, i32 10000)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %9, %1
ret void
9: ; preds = %1, %9
%10 = phi i64 [ %13, %9 ], [ %6, %1 ]
%11 = load i32, i32* @stdout
%12 = call i32 @fwrite(i8* %3, i32 1, i64 %10, i32 %11)
%13 = call i64 @read(i32 %0, i8* %3, i32 10000)
%14 = icmp eq i64 %13, 0
br i1 %14, label %8, label %9
}