#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*/ fw;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int open(char const *, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int write(int, char const *, int);
void setup_fw(const char *fw_path) {
  int fd;
  const char fw[] = "ABCD0123";
  fd = open(fw_path, O_WRONLY | O_CREAT, 0600);
  if (fd < 0)
    die("open failed: %s\n", strerror(errno));
  if (write(fd, fw, sizeof(fw) - 1) != sizeof(fw) - 1)
    die("write failed: %s\n", strerror(errno));
  close(fd);
}


x86 assembly (clang, -O0):
<setup_fw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe9d(%rip),%rax
mov    %rax,-0x15(%rbp)
mov    0xe9b(%rip),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b9 <setup_fw+0x69>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe55(%rip),%rdi
call   1060 <die@plt>
mov    -0xc(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cltq
cmp    $0x8,%rax
je     11f2 <setup_fw+0xa2>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe2d(%rip),%rdi
call   1060 <die@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_fw>:
push   %rbx
sub    $0x10,%rsp
movabs $0x3332313044434241,%rax
31 32 33
mov    %rax,(%rsp)
movb   $0x0,0x8(%rsp)
mov    0x2e59(%rip),%rax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x180,%edx
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11a6 <setup_fw+0x56>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
call   1060 <die@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1030 <write@plt>
cmp    $0x8,%eax
je     11d6 <setup_fw+0x86>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
call   1060 <die@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <close@plt>

LLVM IR (-O0):
@__const.setup_fw.fw = [9 x i8] c"ABCD0123\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [17 x i8] c"open failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"write failed: %s\0A\00"
define void @setup_fw(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [9 x i8]
store i8* %0, i8** %2
%5 = bitcast [9 x i8]* %4 to i8*
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9, i32 384)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %1
%18 = load i32, i32* %3
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%20 = call i32 @write(i32 %18, i8* %19, i32 8)
%21 = sext i32 %20 to i64
%22 = icmp ne i64 %21, 8
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %17
%28 = load i32, i32* %3
%29 = call i32 @close(i32 %28)
ret void
}

LLVM IR (-O2):
@__const.setup_fw.fw = [9 x i8] c"ABCD0123\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [17 x i8] c"open failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [18 x i8] c"write failed: %s\0A\00"
define void @setup_fw(i8* nocapture %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6, i32 384)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %9, %1
%14 = call i32 @write(i32 %7, i8* %3, i32 8)
%15 = icmp eq i32 %14, 8
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = tail call i32 @strerror(i32 %17)
%19 = tail call i32 @die(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %13
%21 = tail call i32 @close(i32 %7)
ret void
}