#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int write(int, char *, int);
int copy_data(int fd1, int fd2) {
  char buffer[1024];
  int conn_status;
  conn_status = read(fd1, buffer, 1024 - 1);
  if (conn_status < 0) {
    perror("read from client");
    exit(EXIT_FAILURE);
  }
  printf("Client -> IRC: %d bytes\n", conn_status);
  conn_status = write(fd2, buffer, conn_status);
  if (conn_status < 0) {
    perror("write: clienttoirc[i * 2 + 1]");
    exit(EXIT_FAILURE);
  }
  return conn_status;
}


x86 assembly (clang, -O0):
<copy_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11a2 <copy_data+0x52>
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x414(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11f6 <copy_data+0xa6>
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x414(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_data>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    $0x3ff,%edx
call   1050 <read@plt>
test   %eax,%eax
js     1196 <copy_data+0x46>
mov    %eax,%ebp
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <write@plt>
test   %eax,%eax
js     119f <copy_data+0x4f>
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe63(%rip),%rdi
jmp    11a6 <copy_data+0x56>
lea    0xe84(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"read from client\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"Client -> IRC: %d bytes\0A\00"
@.str.2 = [30 x i8] c"write: clienttoirc[i * 2 + 1]\00"
define i32 @copy_data(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 1023)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %4
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @write(i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %16
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
@.str = [17 x i8] c"read from client\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"Client -> IRC: %d bytes\0A\00"
@.str.2 = [30 x i8] c"write: clienttoirc[i * 2 + 1]\00"
define i32 @copy_data(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 %0, i8* %4, i32 1023)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%13 = call i32 @write(i32 %1, i8* %4, i32 %5)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
ret i32 %13
}