#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 */
scalar_t__ EXIT_FAILURE;
scalar_t__ EXIT_SUCCESS;
int /*<<< orphan*/ atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
scalar_t__ write_fd(int /*<<< orphan*/, char *, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  int fd;
  char send_buf[256] = "hellowrold";
  if (4 != argc) {
    printf("USAGE : %s <sockfd> <filename> <mode>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = open(argv[2], atoi(argv[3]))) < 0) {
    perror("open");
    exit(errno > 0 ? errno : 255);
  }
  fprintf(stdout, "<recv> %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
  fprintf(stdout, "<send> %s %d\n", send_buf, fd);
  if (write_fd(atoi(argv[1]), send_buf, strlen(send_buf), fd) < 0) {
    perror("write_fd");
    exit(errno > 0 ? errno : 255);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x100,%edx
call   1070 <memcpy@plt>
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
je     11f1 <main+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf23(%rip),%rdi
call   1050 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%rdi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x128(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1277 <main+0xe7>
lea    0xef9(%rip),%rdi
call   1090 <perror@plt>
mov    0x2da6(%rip),%rax
cmpq   $0x0,(%rax)
jle    125a <main+0xca>
mov    0x2d95(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x130(%rbp)
jmp    126b <main+0xdb>
mov    $0xff,%eax
mov    %rax,-0x130(%rbp)
jmp    126b <main+0xdb>
mov    -0x130(%rbp),%rdi
call   10b0 <exit@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r9
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x13c(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x13c(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
call   1030 <write_fd@plt>
cmp    $0x0,%rax
jge    136c <main+0x1dc>
lea    0xe2b(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cb1(%rip),%rax
cmpq   $0x0,(%rax)
jle    134f <main+0x1bf>
mov    0x2ca0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x148(%rbp)
jmp    1360 <main+0x1d0>
mov    $0xff,%eax
mov    %rax,-0x148(%rbp)
jmp    1360 <main+0x1d0>
mov    -0x148(%rbp),%rdi
call   10b0 <exit@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%rdi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe59(%rip),%rsi
mov    %rsp,%rdi
mov    $0x100,%edx
call   1070 <memcpy@plt>
cmp    $0x4,%ebp
jne    11e0 <main+0x50>
mov    0x10(%rbx),%rbp
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1080 <open@plt>
test   %eax,%eax
jns    11fe <main+0x6e>
lea    0xf4c(%rip),%rdi
jmp    126d <main+0xdd>
mov    (%rbx),%rsi
lea    0xf16(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%rdi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x2dc9(%rip),%r14
mov    (%r14),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
mov    0x18(%rbx),%r9
lea    0xf0c(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xf0f(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
call   1030 <write_fd@plt>
test   %rax,%rax
jns    128d <main+0xfd>
lea    0xee1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
mov    $0xff,%edi
cmovg  %rax,%rdi
call   10b0 <exit@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%rdi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.send_buf = [256 x i8] c"hellowrold\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [39 x i8] c"USAGE : %s <sockfd> <filename> <mode>\0A\00"
@EXIT_FAILURE = global i64 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i64 0
@stdout = global i32 0
@.str.2 = [20 x i8] c"<recv> %s %s %s %s\0A\00"
@.str.3 = [14 x i8] c"<send> %s %d\0A\00"
@.str.4 = [9 x i8] c"write_fd\00"
@EXIT_SUCCESS = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [256 x i8]* %7 to i8*
%9 = load i32, i32* %4
%10 = icmp ne i32 4, %9
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i64, i64* @EXIT_FAILURE
%17 = call i32 @exit(i64 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @open(i8* %21, i32 %25)
store i32 %26, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = load i64, i64* @errno
%31 = icmp sgt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i64, i64* @errno
br label %35
34: ; preds = %28
br label %35
35: ; preds = %34, %32
%36 = phi i64 [ %33, %32 ], [ 255, %34 ]
%37 = call i32 @exit(i64 %36)
unreachable
38: ; preds = %18
%39 = load i32, i32* @stdout
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %45, i8* %48, i8* %51)
%53 = load i32, i32* @stdout
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%55 = load i32, i32* %6
%56 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %54, i32 %55)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 @atoi(i8* %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%63 = call i32 @strlen(i8* %62)
%64 = load i32, i32* %6
%65 = call i64 @write_fd(i32 %60, i8* %61, i32 %63, i32 %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %77
67: ; preds = %38
%68 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%69 = load i64, i64* @errno
%70 = icmp sgt i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = load i64, i64* @errno
br label %74
73: ; preds = %67
br label %74
74: ; preds = %73, %71
%75 = phi i64 [ %72, %71 ], [ 255, %73 ]
%76 = call i32 @exit(i64 %75)
unreachable
77: ; preds = %38
%78 = load i64, i64* @EXIT_SUCCESS
%79 = call i32 @exit(i64 %78)
unreachable
}

LLVM IR (-O2):
@__const.main.send_buf = [256 x i8] c"hellowrold\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [39 x i8] c"USAGE : %s <sockfd> <filename> <mode>\0A\00"
@EXIT_FAILURE = global i64 0
@.str.1 = [5 x i8] c"open\00"
@errno = global i64 0
@stdout = global i32 0
@.str.2 = [20 x i8] c"<recv> %s %s %s %s\0A\00"
@.str.3 = [14 x i8] c"<send> %s %d\0A\00"
@.str.4 = [9 x i8] c"write_fd\00"
@EXIT_SUCCESS = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i64, i64* @EXIT_FAILURE
%10 = tail call i32 @exit(i64 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = tail call i32 @open(i8* %13, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %11
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i64, i64* @errno
%22 = icmp sgt i64 %21, 0
%23 = select i1 %22, i64 %21, i64 255
%24 = tail call i32 @exit(i64 %23)
unreachable
25: ; preds = %11
%26 = load i32, i32* @stdout
%27 = load i8*, i8** %1
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = load i8*, i8** %12
%31 = load i8*, i8** %14
%32 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %29, i8* %30, i8* %31)
%33 = load i32, i32* @stdout
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %17)
%35 = load i8*, i8** %28
%36 = call i32 @atoi(i8* %35)
%37 = call i32 @strlen(i8* %4)
%38 = call i64 @write_fd(i32 %36, i8* %4, i32 %37, i32 %17)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %25
%41 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%42 = load i64, i64* @errno
%43 = icmp sgt i64 %42, 0
%44 = select i1 %43, i64 %42, i64 255
%45 = call i32 @exit(i64 %44)
unreachable
46: ; preds = %25
%47 = load i64, i64* @EXIT_SUCCESS
%48 = call i32 @exit(i64 %47)
unreachable
}