#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_CREAT;
int O_RDWR;
int atoi(char *);
scalar_t__ close(int);
int get_cache_file_16(char *, int, char *, int);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  int fd;
  fd = get_cache_file_16("./keys", argc == 2 ? atoi(argv[1]) : 257, "to.der",
                         O_CREAT | O_RDWR);
  if (fd < 0) {
    perror("could not open cache file");
    return -1;
  }
  if (close(fd)) {
    perror("could not close cache file");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1175 <main+0x35>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1182 <main+0x42>
mov    $0x101,%eax
mov    %eax,-0x18(%rbp)
jmp    1182 <main+0x42>
mov    -0x18(%rbp),%esi
mov    0x2e6c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4b(%rip),%rax
or     (%rax),%ecx
lea    0xe62(%rip),%rdi
lea    0xe62(%rip),%rdx
call   1040 <get_cache_file_16@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cf <main+0x8f>
lea    0xe50(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <main+0xc0>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     11f9 <main+0xb9>
lea    0xe40(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <main+0xc0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsi,%rax
mov    $0x101,%esi
cmp    $0x2,%edi
jne    1159 <main+0x19>
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%esi
mov    0x2e98(%rip),%rax
mov    0x2e79(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
lea    0xe8e(%rip),%rdi
lea    0xe8e(%rip),%rdx
call   1040 <get_cache_file_16@plt>
test   %eax,%eax
js     1195 <main+0x55>
mov    %eax,%edi
call   1030 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    119e <main+0x5e>
pop    %rcx
ret
lea    0xe72(%rip),%rdi
jmp    11a5 <main+0x65>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"./keys\00"
@.str.1 = [7 x i8] c"to.der\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [26 x i8] c"could not open cache file\00"
@.str.3 = [27 x i8] c"could not close cache file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
br label %15
14: ; preds = %2
br label %15
15: ; preds = %14, %9
%16 = phi i32 [ %13, %9 ], [ 257, %14 ]
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_RDWR
%19 = or i32 %17, %18
%20 = call i32 @get_cache_file_16(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %32
25: ; preds = %15
%26 = load i32, i32* %6
%27 = call i64 @close(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %32
31: ; preds = %25
store i32 0, i32* %3
br label %32
32: ; preds = %31, %29, %23
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [7 x i8] c"./keys\00"
@.str.1 = [7 x i8] c"to.der\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [26 x i8] c"could not open cache file\00"
@.str.3 = [27 x i8] c"could not close cache file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 257, %2 ]
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_RDWR
%12 = or i32 %11, %10
%13 = tail call i32 @get_cache_file_16(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = tail call i64 @close(i32 %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15, %8
%19 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), %15 ]
%20 = tail call i32 @perror(i8* %19)
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ 0, %15 ], [ -1, %18 ]
ret i32 %22
}