#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*/ atoi(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ write_fd(int /*<<< orphan*/, char *, int, int);
int main(int argc, char *argv[]) {
  int fd;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s <sockfd> <filename> <mode>\n", argv[0]);
    exit(-1);
  }
  if ((fd = open(argv[2], atoi(argv[3]))) < 0)
    exit((errno > 0) ? errno : 255);
  if (write_fd(atoi(argv[1]), "", 1, fd) < 0)
    exit((errno > 0) ? errno : 255);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffffffffffff,%rdi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1060 <atoi@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1203 <main+0xb3>
mov    0x2e09(%rip),%rax
cmpq   $0x0,(%rax)
jle    11ec <main+0x9c>
mov    0x2df8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11fa <main+0xaa>
mov    $0xff,%eax
mov    %rax,-0x28(%rbp)
jmp    11fa <main+0xaa>
mov    -0x28(%rbp),%rdi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%ecx
lea    0xe09(%rip),%rsi
mov    $0x1,%edx
call   1030 <write_fd@plt>
cmp    $0x0,%rax
jge    126b <main+0x11b>
mov    0x2da1(%rip),%rax
cmpq   $0x0,(%rax)
jle    1254 <main+0x104>
mov    0x2d90(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1262 <main+0x112>
mov    $0xff,%eax
mov    %rax,-0x30(%rbp)
jmp    1262 <main+0x112>
mov    -0x30(%rbp),%rdi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11bf <main+0x6f>
mov    0x10(%rbx),%rbp
mov    0x18(%rbx),%rdi
call   1060 <atoi@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1050 <open@plt>
test   %eax,%eax
js     11a4 <main+0x54>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
call   1060 <atoi@plt>
lea    0xe9d(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
mov    %ebp,%ecx
call   1030 <write_fd@plt>
test   %rax,%rax
js     11a4 <main+0x54>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
test   %rax,%rax
mov    $0xff,%edi
cmovg  %rax,%rdi
call   1070 <exit@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe2e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffffffffffff,%rdi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"Usage: %s <sockfd> <filename> <mode>\0A\00"
@errno = global i64 0
@.str.1 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 4
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i64 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = call i32 @open(i8* %19, i32 %23)
store i32 %24, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %16
%27 = load i64, i64* @errno
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i64, i64* @errno
br label %32
31: ; preds = %26
br label %32
32: ; preds = %31, %29
%33 = phi i64 [ %30, %29 ], [ 255, %31 ]
%34 = call i32 @exit(i64 %33)
unreachable
35: ; preds = %16
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = load i32, i32* %6
%41 = call i64 @write_fd(i32 %39, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %35
%44 = load i64, i64* @errno
%45 = icmp sgt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = load i64, i64* @errno
br label %49
48: ; preds = %43
br label %49
49: ; preds = %48, %46
%50 = phi i64 [ %47, %46 ], [ 255, %48 ]
%51 = call i32 @exit(i64 %50)
unreachable
52: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"Usage: %s <sockfd> <filename> <mode>\0A\00"
@errno = global i64 0
@.str.1 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i64 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @open(i8* %11, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = load i64, i64* @errno
%19 = icmp sgt i64 %18, 0
%20 = select i1 %19, i64 %18, i64 255
%21 = tail call i32 @exit(i64 %20)
unreachable
22: ; preds = %9
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = tail call i64 @write_fd(i32 %25, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %15)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %22
%29 = load i64, i64* @errno
%30 = icmp sgt i64 %29, 0
%31 = select i1 %30, i64 %29, i64 255
%32 = tail call i32 @exit(i64 %31)
unreachable
33: ; preds = %22
ret i32 0
}