#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 EXIT_FAILURE;
int _open_socket();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/);
scalar_t__ parse_opts(int, char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int write(int, char *, int);
int main(int argc, char **argv) {
  int sockfd;
  char buf[4096];
  int ret;
  if (parse_opts(argc, argv))
    exit(-1);
  sockfd = _open_socket();
  if (sockfd < 0) {
    exit(EXIT_FAILURE);
  }
  int bytes;
  while ((bytes = fread(buf, sizeof(char), 4096, stdin))) {
    ret = write(sockfd, buf, bytes);
    if (ret != bytes) {
      fprintf(stderr, "write err");
      exit(-1);
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <parse_opts@plt>
cmp    $0x0,%rax
je     11a9 <main+0x39>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1090 <_open_socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cb <main+0x5b>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    11d0 <main+0x60>
lea    -0x1020(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x1028(%rbp)
cmp    $0x0,%eax
je     124f <main+0xdf>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x1024(%rbp),%eax
cmp    -0x1028(%rbp),%eax
je     124a <main+0xda>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11d0 <main+0x60>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
call   1050 <parse_opts@plt>
test   %rax,%rax
jne    1203 <main+0x93>
xor    %eax,%eax
call   1090 <_open_socket@plt>
test   %eax,%eax
js     120d <main+0x9d>
mov    %eax,%r14d
mov    0x2e4c(%rip),%r15
mov    %rsp,%rbx
nop
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     11eb <main+0x7b>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     11a0 <main+0x30>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"write err\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i64 @parse_opts(i32 %10, i8** %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i32 (...) @_open_socket()
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %16
br label %24
24: ; preds = %41, %23
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i32 @fread(i8* %25, i32 1, i32 4096, i32 %26)
store i32 %27, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %24
%30 = load i32, i32* %6
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %9
%33 = call i32 @write(i32 %30, i8* %31, i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %29
br label %24
42: ; preds = %24
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
ret i32 0
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"write err\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @parse_opts(i32 %0, i8** %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = tail call i32 (...) @_open_socket()
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %9, %19
%16 = load i32, i32* @stdin
%17 = call i32 @fread(i8* %4, i32 1, i32 4096, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %15
%20 = call i32 @write(i32 %10, i8* %4, i32 %17)
%21 = icmp eq i32 %20, %17
br i1 %21, label %15, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %15
%27 = call i32 @close(i32 %10)
ret i32 0
}