#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;
char *basename(char *);
int copy_to_file_from_fd(int, char *);
char *getenv(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ trio_fprintf(int /*<<< orphan*/, char *);
char *save_object_to_fs() {
  char *real_obj_path = NULL;
  char *real_obj_name = NULL;
  int obj = 0;
  int fd_dev = 0;
  real_obj_path = getenv("PATH_INFO");
  if (!real_obj_path)
    return NULL;
  real_obj_name = basename(real_obj_path);
  if (!real_obj_name)
    return NULL;
  fd_dev = open("/dev/input", O_RDONLY);
  if (fd_dev <= 0)
    return NULL;
  obj = copy_to_file_from_fd(fd_dev, real_obj_name);
  if (obj <= 0) {
    trio_fprintf(stderr, "Indexer settings not loaded\n");
    return NULL;
  }
  return real_obj_name;
}


x86 assembly (clang, -O0):
<save_object_to_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <save_object_to_fs+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    1235 <save_object_to_fs+0xe5>
mov    -0x10(%rbp),%rdi
call   1050 <basename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <save_object_to_fs+0x73>
movq   $0x0,-0x8(%rbp)
jmp    1235 <save_object_to_fs+0xe5>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     11f2 <save_object_to_fs+0xa2>
movq   $0x0,-0x8(%rbp)
jmp    1235 <save_object_to_fs+0xe5>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <copy_to_file_from_fd@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     122d <save_object_to_fs+0xdd>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1040 <trio_fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1235 <save_object_to_fs+0xe5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_object_to_fs>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ae <save_object_to_fs+0x5e>
mov    %rax,%rdi
call   1050 <basename@plt>
test   %rax,%rax
je     11ae <save_object_to_fs+0x5e>
mov    %rax,%rbx
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jle    11ae <save_object_to_fs+0x5e>
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <copy_to_file_from_fd@plt>
test   %eax,%eax
jg     11b0 <save_object_to_fs+0x60>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <trio_fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"PATH_INFO\00"
@.str.1 = [11 x i8] c"/dev/input\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [29 x i8] c"Indexer settings not loaded\0A\00"
define i8* @save_object_to_fs() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* null, i8** %2
store i8* null, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
store i8* null, i8** %1
br label %33
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = call i8* @basename(i8* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
store i8* null, i8** %1
br label %33
16: ; preds = %10
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i8* null, i8** %1
br label %33
22: ; preds = %16
%23 = load i32, i32* %5
%24 = load i8*, i8** %3
%25 = call i32 @copy_to_file_from_fd(i32 %23, i8* %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = call i32 @trio_fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %33
31: ; preds = %22
%32 = load i8*, i8** %3
store i8* %32, i8** %1
br label %33
33: ; preds = %31, %28, %21, %15, %9
%34 = load i8*, i8** %1
ret i8* %34
}

LLVM IR (-O2):
@.str = [10 x i8] c"PATH_INFO\00"
@.str.1 = [11 x i8] c"/dev/input\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [29 x i8] c"Indexer settings not loaded\0A\00"
define i8* @save_object_to_fs() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %16, label %3
3: ; preds = %0
%4 = tail call i8* @basename(i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 1
br i1 %9, label %16, label %10
10: ; preds = %6
%11 = tail call i32 @copy_to_file_from_fd(i32 %8, i8* %4)
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @trio_fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %10, %6, %3, %0, %13
%17 = phi i8* [ null, %13 ], [ null, %0 ], [ null, %3 ], [ null, %6 ], [ %4, %10 ]
ret i8* %17
}