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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void cat(int client, FILE *resource) {
  char buf[1024];
  fgets(buf, sizeof(buf), resource);
  while (!feof(resource)) {
    send(client, buf, strlen(buf), 0);
    fgets(buf, sizeof(buf), resource);
  }
  printf("send index.html\n");
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1195 <cat+0x45>
jmp    11e8 <cat+0x98>
mov    -0x4(%rbp),%eax
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x41c(%rbp),%edi
mov    -0x418(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
jmp    1177 <cat+0x27>
lea    0xe11(%rip),%rdi
call   1050 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11b3 <cat+0x63>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1180 <cat+0x30>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"send index.html\0A\00"
define void @cat(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [1024 x i8]
store i32 %0, i32* %3
store i32* %1, i32** %4
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = load i32*, i32** %4
%8 = call i32 @fgets(i8* %6, i32 1024, i32* %7)
br label %9
9: ; preds = %14, %2
%10 = load i32*, i32** %4
%11 = call i32 @feof(i32* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* %3
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @send(i32 %15, i8* %16, i32 %18, i32 0)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = load i32*, i32** %4
%22 = call i32 @fgets(i8* %20, i32 1024, i32* %21)
br label %9
23: ; preds = %9
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@str = [16 x i8] c"send index.html\00"
define void @cat(i32 %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @fgets(i8* %4, i32 1024, i32* %1)
%6 = call i32 @feof(i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2, %8
%9 = call i32 @strlen(i8* %4)
%10 = call i32 @send(i32 %0, i8* %4, i32 %9, i32 0)
%11 = call i32 @fgets(i8* %4, i32 1024, i32* %1)
%12 = call i32 @feof(i32* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %8, %2
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
ret void
}