#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*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ msg(int, char *, int, char *);
char *strerror(int /*<<< orphan*/);
int write(int, void *, int);
void emu_file_write(int fd, void *bytes, int len) {
  int rc;
  if ((rc = write(fd, bytes, len)) != len) {
    msg(0x100, "Failed to write bytes to emulation file %d %s\n", rc,
        rc == -1 ? strerror(errno) : "");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<emu_file_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
je     11c6 <emu_file_write+0x86>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1194 <emu_file_write+0x54>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,-0x28(%rbp)
jmp    11a4 <emu_file_write+0x64>
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11a4 <emu_file_write+0x64>
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x100,%edi
lea    0xe49(%rip),%rsi
call   1060 <msg@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emu_file_write>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
call   1030 <write@plt>
cmp    %ebp,%eax
jne    1155 <emu_file_write+0x15>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    116f <emu_file_write+0x2f>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rcx
jmp    1176 <emu_file_write+0x36>
lea    0xeb8(%rip),%rcx
lea    0xe83(%rip),%rsi
mov    $0x100,%edi
mov    %ebx,%edx
call   1060 <msg@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Failed to write bytes to emulation file %d %s\0A\00"
@errno = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define void @emu_file_write(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @write(i32 %8, i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %6
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %3
%15 = load i32, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
br label %22
21: ; preds = %14
br label %22
22: ; preds = %21, %18
%23 = phi i8* [ %20, %18 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %21 ]
%24 = call i32 @msg(i32 256, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"Failed to write bytes to emulation file %d %s\0A\00"
@errno = global i32 0
@.str.1 = [1 x i8] zeroinitializer
define void @emu_file_write(i32 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @write(i32 %0, i8* %1, i32 %2)
%5 = icmp eq i32 %4, %2
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = icmp eq i32 %4, -1
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
br label %11
11: ; preds = %6, %8
%12 = phi i8* [ %10, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %6 ]
%13 = tail call i32 @msg(i32 256, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %3
ret void
}