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

/* Variables and functions */
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void write_pass_fd(int srcfd, int dstfd) {
  int done = 0;
  while (!done) {
    char buffer[40];
    int i;
    int numread = read(srcfd, buffer, sizeof(buffer));
    done = (numread < 1);
    for (i = 0; i < numread && !done; ++i) {
      if (buffer[i] != '\n')
        write(dstfd, buffer + i, 1);
      else
        done = 1;
    }
  }
  write(dstfd, "\n", 1);
}


x86 assembly (clang, -O0):
<write_pass_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    114b <write_pass_fd+0x2b>
jmp    11f0 <write_pass_fd+0xd0>
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x28,%edx
call   1040 <read@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x1,-0x48(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%ecx
xor    %eax,%eax
cmp    -0x48(%rbp),%ecx
mov    %al,-0x49(%rbp)
jge    1192 <write_pass_fd+0x72>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11a2 <write_pass_fd+0x82>
jmp    11eb <write_pass_fd+0xcb>
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     11d1 <write_pass_fd+0xb1>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
movslq -0x44(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11d8 <write_pass_fd+0xb8>
movl   $0x1,-0xc(%rbp)
jmp    11dd <write_pass_fd+0xbd>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1175 <write_pass_fd+0x55>
jmp    1135 <write_pass_fd+0x15>
mov    -0x8(%rbp),%edi
lea    0xe06(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pass_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r12d
mov    %edi,%r15d
mov    %rsp,%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x28,%edx
call   1040 <read@plt>
xor    %ecx,%ecx
test   %eax,%eax
setle  %dl
jle    11a0 <write_pass_fd+0x80>
mov    %eax,%r13d
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%r14d
cmp    $0xa,%r14b
je     11a9 <write_pass_fd+0x89>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %ecx,%ecx
cmp    $0xa,%r14b
je     11a2 <write_pass_fd+0x82>
add    $0x1,%rbp
lea    0x1(%rbx),%rax
cmp    %r13,%rbx
mov    %rax,%rbx
jb     1160 <write_pass_fd+0x40>
jmp    11a2 <write_pass_fd+0x82>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %dl,%cl
test   %ecx,%ecx
mov    %rsp,%rbp
je     1137 <write_pass_fd+0x17>
lea    0xe50(%rip),%rsi
mov    %r12d,%edi
mov    $0x1,%edx
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @write_pass_fd(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [40 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %49, %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %50
13: ; preds = %9
%14 = load i32, i32* %3
%15 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 40)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 1
%19 = zext i1 %18 to i32
store i32 %19, i32* %5
store i32 0, i32* %7
br label %20
20: ; preds = %46, %13
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br label %28
28: ; preds = %24, %20
%29 = phi i1 [ false, %20 ], [ %27, %24 ]
br i1 %29, label %30, label %49
30: ; preds = %28
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %44
37: ; preds = %30
%38 = load i32, i32* %4
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = call i32 @write(i32 %38, i8* %42, i32 1)
br label %45
44: ; preds = %30
store i32 1, i32* %5
br label %45
45: ; preds = %44, %37
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %20
49: ; preds = %28
br label %9
50: ; preds = %9
%51 = load i32, i32* %4
%52 = call i32 @write(i32 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @write_pass_fd(i32 %0, i32 %1) {
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %23
%6 = call i32 @read(i32 %0, i8* %4, i32 40)
%7 = icmp slt i32 %6, 1
%8 = zext i1 %7 to i32
%9 = icmp sgt i32 %6, 0
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = zext i32 %6 to i64
br label %12
12: ; preds = %10, %18
%13 = phi i64 [ 0, %10 ], [ %20, %18 ]
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %12
br label %26
18: ; preds = %12
%19 = call i32 @write(i32 %1, i8* %14, i32 1)
%20 = add nuw nsw i64 %13, 1
%21 = icmp uge i64 %20, %11
%22 = or i1 %16, %21
br i1 %22, label %23, label %12
23: ; preds = %18, %5
%24 = phi i32 [ %8, %5 ], [ 0, %18 ]
%25 = icmp eq i32 %24, 0
br i1 %25, label %5, label %26
26: ; preds = %23, %17
%27 = tail call i32 @write(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
ret void
}