#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 */
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int write(int, char *, int);
int write_port(int fd, char *data) {
  int data_len = sizeof(data) - 1;
  int num_bytes_written = write(fd, data, data_len);
  if (num_bytes_written < 0) {
    fprintf(stderr, "write_port: Failed to write \"%s\"\n", data);
    exit(-1);
  } else {
    fprintf(stdout, "write_port: Wrote \"%s\"\n", data);
  }
  return num_bytes_written;
}


x86 assembly (clang, -O0):
<write_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1185 <write_port+0x55>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_port>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x7,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1167 <write_port+0x37>
mov    %eax,%ebp
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xecc(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"write_port: Failed to write \22%s\22\0A\00"
@stdout = global i32 0
@.str.1 = [24 x i8] c"write_port: Wrote \22%s\22\0A\00"
define i32 @write_port(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 7, i32* %5
%7 = load i32, i32* %3
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = call i32 @write(i32 %7, i8* %8, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @stdout
%20 = load i8*, i8** %4
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18
%23 = load i32, i32* %6
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"write_port: Failed to write \22%s\22\0A\00"
@stdout = global i32 0
@.str.1 = [24 x i8] c"write_port: Wrote \22%s\22\0A\00"
define i32 @write_port(i32 %0, i8* %1) {
%3 = tail call i32 @write(i32 %0, i8* %1, i32 7)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = load i32, i32* @stdout
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %1)
ret i32 %3
}