#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*/ EXIT_FAILURE;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ dprintf(int, char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ get_duid_path(char *, int);
int open(char *, int, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int open_duidfile_write(void) {
  char duidfile[PATH_MAX];
  get_duid_path(duidfile, sizeof duidfile);
  int fd = open(duidfile, O_WRONLY | O_TRUNC | O_CREAT, 0644);
  if (fd < 0)
    do {
      dprintf(2, "Failed to open duidfile '%s' for writing: %s", duidfile,
              strerror(errno));
      dprintf(2, "\n");
      exit(EXIT_FAILURE);
    } while (0);
  return fd;
}


x86 assembly (clang, -O0):
<open_duidfile_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x20(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
mov    %eax,%esi
call   1040 <get_duid_path@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
mov    0x2e50(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120e <open_duidfile_write+0xbe>
jmp    11c6 <open_duidfile_write+0x76>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    $0x2,%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_duidfile_write>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1040 <get_duid_path@plt>
mov    0x2e2e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11ae <open_duidfile_write+0x5e>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3d(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <dprintf@plt>
lea    0xe52(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <dprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str = [45 x i8] c"Failed to open duidfile '%s' for writing: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @open_duidfile_write() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %1
%7 = alloca i8, i64 %5
store i64 %5, i64* %2
%8 = trunc i64 %5 to i32
%9 = call i32 @get_duid_path(i8* %7, i32 %8)
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %7, i32 %14, i32 420)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %0
br label %19
19: ; preds = %18
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %21)
%23 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; No predecessors!
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27, %0
%29 = load i32, i32* %3
%30 = load i8*, i8** %1
ret i32 %29
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str = [45 x i8] c"Failed to open duidfile '%s' for writing: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @open_duidfile_write() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i32 @get_duid_path(i8* %3, i32 %1)
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %6, %5
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %3, i32 %9, i32 420)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %0
%13 = load i32, i32* @errno
%14 = call i32 @strerror(i32 %13)
%15 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %14)
%16 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %0
ret i32 %10
}