#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 gopherOpen(char const *, int, char const *);
int read(int, char *, int);
int /*<<< orphan*/ warn(char *);
scalar_t__ write(int, char *, int);
int gopherTransfer(const char *host, int port, const char *path, int wfd) {
  int rfd = gopherOpen(host, port, path);
  if (rfd < 0)
    return -1;
  int n;
  char buf[256];
  while ((n = read(rfd, buf, 255)) > 0)
    if (write(wfd, buf, n) < 0)
      warn("gopherTransfer");
  return 0;
}


x86 assembly (clang, -O0):
<gopherTransfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <gopherOpen@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1182 <gopherTransfer+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <gopherTransfer+0x9b>
jmp    1187 <gopherTransfer+0x47>
mov    -0x28(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0xff,%edx
call   1050 <read@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    11d4 <gopherTransfer+0x94>
mov    -0x24(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    11cf <gopherTransfer+0x8f>
lea    0xe36(%rip),%rdi
call   1030 <warn@plt>
jmp    1187 <gopherTransfer+0x47>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gopherTransfer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %ecx,%r14d
call   1060 <gopherOpen@plt>
test   %eax,%eax
js     11b3 <gopherTransfer+0x73>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xff,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11af <gopherTransfer+0x6f>
mov    %rsp,%rbx
lea    0xe88(%rip),%r15
jmp    1193 <gopherTransfer+0x53>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11af <gopherTransfer+0x6f>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1180 <gopherTransfer+0x40>
mov    %r15,%rdi
call   1030 <warn@plt>
jmp    1180 <gopherTransfer+0x40>
xor    %eax,%eax
jmp    11b8 <gopherTransfer+0x78>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"gopherTransfer\00"
define i32 @gopherTransfer(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [256 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = load i8*, i8** %8
%16 = call i32 @gopherOpen(i8* %13, i32 %14, i8* %15)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 -1, i32* %5
br label %36
20: ; preds = %4
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %10
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 255)
store i32 %24, i32* %11
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %21
%27 = load i32, i32* %9
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%29 = load i32, i32* %11
%30 = call i64 @write(i32 %27, i8* %28, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
br label %21
35: ; preds = %21
store i32 0, i32* %5
br label %36
36: ; preds = %35, %19
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [15 x i8] c"gopherTransfer\00"
define i32 @gopherTransfer(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [256 x i8]
%6 = tail call i32 @gopherOpen(i8* %0, i32 %1, i8* %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32 @read(i32 %6, i8* %9, i32 255)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8, %18
%13 = phi i32 [ %19, %18 ], [ %10, %8 ]
%14 = call i64 @write(i32 %3, i8* %9, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @warn(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = call i32 @read(i32 %6, i8* %9, i32 255)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %12, label %21
21: ; preds = %18, %8
br label %22
22: ; preds = %4, %21
%23 = phi i32 [ 0, %21 ], [ -1, %4 ]
ret i32 %23
}