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


x86 assembly (clang, -O0):
<open_duidfile_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%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    0x2e5a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e5 <open_duidfile_read+0xa5>
jmp    11a1 <open_duidfile_read+0x61>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rdx
mov    %eax,%ecx
mov    $0x2,%edi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    $0x2,%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
jmp    11e0 <open_duidfile_read+0xa0>
jmp    11e5 <open_duidfile_read+0xa5>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_duidfile_read>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ea2(%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    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    11bf <open_duidfile_read+0x7f>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe65(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <dprintf@plt>
lea    0xe7a(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <dprintf@plt>
mov    %r14d,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@O_RDONLY = global i32 0
@.str = [45 x i8] c"Failed to open duidfile '%s' for reading: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @open_duidfile_read() {
%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_RDONLY
%11 = call i32 @open(i8* %7, i32 %10, i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %0
br label %15
15: ; preds = %14
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %17)
%19 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %15
br label %21
21: ; preds = %20
br label %22
22: ; preds = %21, %0
%23 = load i32, i32* %3
%24 = load i8*, i8** %1
ret i32 %23
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@O_RDONLY = global i32 0
@.str = [45 x i8] c"Failed to open duidfile '%s' for reading: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @open_duidfile_read() {
%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_RDONLY
%6 = call i32 @open(i8* %3, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = call i32 @strerror(i32 %9)
%11 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %10)
%12 = call i32 (i32, i8*, ...) @dprintf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %8, %0
ret i32 %6
}