#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 cache {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int cache_loadfile(struct cache *, int /*<<< orphan*/ *, char const *,
                   unsigned int);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char const *, char *);
int cache_loadpath(struct cache *C, const char *path, const char *origin,
                   unsigned ttl) {
  FILE *fp;
  int error;
  if (!strcmp(path, "-"))
    return cache_loadfile(C, stdin, origin, ttl);
  if (!(fp = fopen(path, "r")))
    return errno;
  error = cache_loadfile(C, fp, origin, ttl);
  fclose(fp);
  return error;
}


x86 assembly (clang, -O0):
<cache_loadpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1192 <cache_loadpath+0x52>
mov    -0x10(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <cache_loadfile@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <cache_loadpath+0xa7>
mov    -0x18(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11c1 <cache_loadpath+0x81>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11e7 <cache_loadpath+0xa7>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <cache_loadfile@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_loadpath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     119c <cache_loadpath+0x5c>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11be <cache_loadpath+0x7e>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1040 <cache_loadfile@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    11c7 <cache_loadpath+0x87>
mov    0x2e45(%rip),%rax
mov    (%rax),%rsi
mov    %rbp,%rdi
mov    %r15,%rdx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <cache_loadfile@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.cache = type { i32 }
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @cache_loadpath(%struct.cache* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.cache*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store %struct.cache* %0, %struct.cache** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %7
%13 = call i32 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %4
%16 = load %struct.cache*, %struct.cache** %6
%17 = load i32*, i32** @stdin
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = call i32 @cache_loadfile(%struct.cache* %16, i32* %17, i8* %18, i32 %19)
store i32 %20, i32* %5
br label %36
21: ; preds = %4
%22 = load i8*, i8** %7
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %10
%24 = icmp ne i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = load i32, i32* @errno
store i32 %26, i32* %5
br label %36
27: ; preds = %21
%28 = load %struct.cache*, %struct.cache** %6
%29 = load i32*, i32** %10
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = call i32 @cache_loadfile(%struct.cache* %28, i32* %29, i8* %30, i32 %31)
store i32 %32, i32* %11
%33 = load i32*, i32** %10
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %11
store i32 %35, i32* %5
br label %36
36: ; preds = %27, %25, %15
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
%struct.cache = type { i32 }
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @cache_loadpath(%struct.cache* %0, i8* nocapture %1, i8* %2, i32 %3) {
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32*, i32** @stdin
%9 = tail call i32 @cache_loadfile(%struct.cache* %0, i32* %8, i8* %2, i32 %3)
br label %18
10: ; preds = %4
%11 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* @errno
br label %18
15: ; preds = %10
%16 = tail call i32 @cache_loadfile(%struct.cache* %0, i32* %11, i8* %2, i32 %3)
%17 = tail call i32 @fclose(i32* %11)
br label %18
18: ; preds = %15, %13, %7
%19 = phi i32 [ %16, %15 ], [ %14, %13 ], [ %9, %7 ]
ret i32 %19
}