#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*/ FILE;

/* Variables and functions */
int fileno(int /*<<< orphan*/ *);
size_t read(int, char *, int);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void cat(int client, FILE *resource) {
  int fd = fileno(resource);
  char buf[1024];
  size_t length = -1;
  while ((length = read(fd, buf, 1024)) > 0) {
    send(client, buf, strlen(buf), 0);
  }
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fileno@plt>
mov    %eax,-0x14(%rbp)
movq   $0xffffffffffffffff,-0x428(%rbp)
ff ff ff ff
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jbe    11cc <cat+0x8c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x434(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
jmp    1169 <cat+0x29>
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1060 <fileno@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
je     119b <cat+0x5b>
mov    %rsp,%rbx
nop
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    1170 <cat+0x30>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @cat(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca i64
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = load i32*, i32** %4
%9 = call i32 @fileno(i32* %8)
store i32 %9, i32* %5
store i64 -1, i64* %7
br label %10
10: ; preds = %15, %2
%11 = load i32, i32* %5
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 1024)
store i64 %13, i64* %7
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @send(i32 %16, i8* %17, i32 %19, i32 0)
br label %10
21: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @cat(i32 %0, i32* nocapture %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32 @fileno(i32* %1)
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i64 @read(i32 %4, i8* %5, i32 1024)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2, %8
%9 = call i32 @strlen(i8* %5)
%10 = call i32 @send(i32 %0, i8* %5, i32 %9, i32 0)
%11 = call i64 @read(i32 %4, i8* %5, i32 1024)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %8
13: ; preds = %8, %2
ret void
}