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

/* Variables and functions */
int STDOUT_FILENO;
size_t read(int, char *, int);
size_t strlen(char const *);
int /*<<< orphan*/ write(int, char const *, size_t);
void client(const char *pathname, int read_fd, int write_fd) {
  size_t len;
  ssize_t n;
  char buff[1024];
  len = strlen(pathname);
  if (buff[len - 1] == '\n') {
    len--;
  }
  write(write_fd, pathname, len);
  while ((n = read(read_fd, buff, 1024)) > 0) {
    write(STDOUT_FILENO, buff, n);
  }
}


x86 assembly (clang, -O0):
<client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1177 <client+0x47>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    11c7 <client+0x97>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
jmp    1187 <client+0x57>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    -0x1(%rax),%rdx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
je     11a2 <client+0x72>
mov    0x2e7e(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
jne    1180 <client+0x50>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
define void @client(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = sub i64 %12, 1
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i64, i64* %7
%20 = add i64 %19, -1
store i64 %20, i64* %7
br label %21
21: ; preds = %18, %3
%22 = load i32, i32* %6
%23 = load i8*, i8** %4
%24 = load i64, i64* %7
%25 = call i32 @write(i32 %22, i8* %23, i64 %24)
br label %26
26: ; preds = %31, %21
%27 = load i32, i32* %5
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%29 = call i64 @read(i32 %27, i8* %28, i32 1024)
store i64 %29, i64* %8
%30 = icmp ugt i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32, i32* @STDOUT_FILENO
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = load i64, i64* %8
%35 = call i32 @write(i32 %32, i8* %33, i64 %34)
br label %26
36: ; preds = %26
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
define void @client(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = add i64 %6, -1
%8 = tail call i32 @write(i32 %2, i8* %0, i64 %7)
%9 = call i64 @read(i32 %1, i8* %5, i32 1024)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %3, %11
%12 = phi i64 [ %15, %11 ], [ %9, %3 ]
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @write(i32 %13, i8* %5, i64 %12)
%15 = call i64 @read(i32 %1, i8* %5, i32 1024)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %11
17: ; preds = %11, %3
ret void
}