#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 */
struct file_cache {
  int dummy;
};

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ cached_name(struct file_cache *, char const *, char *);
int /*<<< orphan*/ cctools_debug(long long, char *, char const *, ...);
int /*<<< orphan*/ errno;
int rename(char const *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int file_cache_commit(struct file_cache *f, const char *path, const char *txn) {
  int result;
  char lpath[PATH_MAX];
  cached_name(f, path, lpath);
  cctools_debug((1LL << 30), "commit %s %s %s", path, txn, lpath);
  result = rename(txn, lpath);
  if (result < 0)
    cctools_debug((1LL << 30), "commit failed: %s", strerror(errno));
  return result;
}


x86 assembly (clang, -O0):
<file_cache_commit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <cached_name@plt>
mov    -0x38(%rbp),%r8
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x40000000,%edi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%rdi
call   1050 <rename@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ea <file_cache_commit+0xaa>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
movslq %eax,%rdx
mov    $0x40000000,%edi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1030 <cctools_debug@plt>
mov    -0x1c(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_cache_commit>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdx
call   1040 <cached_name@plt>
lea    0xe87(%rip),%rsi
mov    $0x40000000,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <cctools_debug@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <rename@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11c3 <file_cache_commit+0x83>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
movslq %eax,%rdx
lea    0xe59(%rip),%rsi
mov    $0x40000000,%edi
xor    %eax,%eax
call   1030 <cctools_debug@plt>
mov    %ebx,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.file_cache = type { i32 }
@PATH_MAX = global i32 0
@.str = [16 x i8] c"commit %s %s %s\00"
@.str.1 = [18 x i8] c"commit failed: %s\00"
@errno = global i32 0
define i32 @file_cache_commit(%struct.file_cache* %0, i8* %1, i8* %2) {
%4 = alloca %struct.file_cache*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store %struct.file_cache* %0, %struct.file_cache** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
%14 = load %struct.file_cache*, %struct.file_cache** %4
%15 = load i8*, i8** %5
%16 = call i32 @cached_name(%struct.file_cache* %14, i8* %15, i8* %13)
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1073741824, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i8* %13)
%20 = load i8*, i8** %6
%21 = call i32 @rename(i8* %20, i8* %13)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %3
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
%29 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1073741824, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %24, %3
%31 = load i32, i32* %7
%32 = load i8*, i8** %8
ret i32 %31
}

LLVM IR (-O2):
%struct.file_cache = type { i32 }
@PATH_MAX = global i32 0
@.str = [16 x i8] c"commit %s %s %s\00"
@.str.1 = [18 x i8] c"commit failed: %s\00"
@errno = global i32 0
define i32 @file_cache_commit(%struct.file_cache* %0, i8* %1, i8* %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @cached_name(%struct.file_cache* %0, i8* %1, i8* %6)
%8 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1073741824, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i8* %6)
%9 = call i32 @rename(i8* %2, i8* %6)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 1073741824, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %11, %3
ret i32 %9
}