#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 O_RDWR;
int O_SYNC;
scalar_t__ asprintf(char **, char *, char const *);
int /*<<< orphan*/ free(char *);
int open(char *, int);
int get_loading_fd(const char *device) {
  int fd = -1;
  char *loading_path = NULL;
  if (asprintf(&loading_path, "%s/loading", device) < 0) {
    ;
    return -1;
  };
  fd = open(loading_path, O_RDWR | O_SYNC);
  if (fd < 0)
    ;
  free(loading_path);
  return fd;
}


x86 assembly (clang, -O0):
<get_loading_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%rax
jge    1175 <get_loading_fd+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b1 <get_loading_fd+0x81>
mov    -0x20(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a2 <get_loading_fd+0x72>
jmp    11a2 <get_loading_fd+0x72>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_loading_fd>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
lea    0xeb8(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <asprintf@plt>
test   %rax,%rax
js     1181 <get_loading_fd+0x51>
mov    0x8(%rsp),%rdi
mov    0x2e85(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    1186 <get_loading_fd+0x56>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s/loading\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
define i32 @get_loading_fd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 -1, i32* %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = call i64 @asprintf(i8** %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %23
10: ; preds = %1
%11 = load i8*, i8** %5
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_SYNC
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %11, i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
br label %19
19: ; preds = %18, %10
%20 = load i8*, i8** %5
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s/loading\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
define i32 @get_loading_fd(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_SYNC
%10 = or i32 %9, %8
%11 = call i32 @open(i8* %7, i32 %10)
%12 = load i8*, i8** %2
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %1, %6
%15 = phi i32 [ %11, %6 ], [ -1, %1 ]
ret i32 %15
}