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

/* Variables and functions */
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void duplicate_input(void) {
  char buff[3750];
  int bytes_read;
  while (1) {
    bytes_read = read(0, buff, 3750);
    write(1, buff, bytes_read);
    if (buff[bytes_read - 1] == 0)
      break;
    buff[0] = 0;
  }
}


x86 assembly (clang, -O0):
<duplicate_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0xec0,%rsp
lea    -0xeb0(%rbp),%rsi
xor    %edi,%edi
mov    $0xea6,%edx
call   1040 <read@plt>
mov    %eax,-0xeb4(%rbp)
lea    -0xeb0(%rbp),%rsi
mov    -0xeb4(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0xeb4(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0xeb0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    117c <duplicate_input+0x5c>
jmp    1188 <duplicate_input+0x68>
movb   $0x0,-0xeb0(%rbp)
jmp    112b <duplicate_input+0xb>
add    $0xec0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duplicate_input>:
push   %rbp
push   %rbx
sub    $0xea8,%rsp
mov    %rsp,%rbx
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xea6,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
movslq %ebp,%rax
cmpb   $0x0,-0x1(%rax,%rbx,1)
je     1160 <duplicate_input+0x40>
movb   $0x0,(%rsp)
jmp    1130 <duplicate_input+0x10>
add    $0xea8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @duplicate_input() {
%1 = alloca [3750 x i8]
%2 = alloca i32
br label %3
3: ; preds = %0, %17
%4 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 3750)
store i32 %5, i32* %2
%6 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @write(i32 1, i8* %6, i32 %7)
%9 = load i32, i32* %2
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
br label %19
17: ; preds = %3
%18 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 0
store i8 0, i8* %18
br label %3
19: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @duplicate_input() {
%1 = alloca [3750 x i8]
%2 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 3750)
%4 = call i32 @write(i32 1, i8* %2, i32 %3)
%5 = add nsw i32 %3, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %0, %10
store i8 0, i8* %2
%11 = call i32 @read(i32 0, i8* %2, i32 3750)
%12 = call i32 @write(i32 1, i8* %2, i32 %11)
%13 = add nsw i32 %11, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [3750 x i8], [3750 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %0
ret void
}