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

/* Variables and functions */
int /*<<< orphan*/ compute_cache_ids();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ save_cdec(int /*<<< orphan*/ *);
int /*<<< orphan*/ save_cintrp(int /*<<< orphan*/ *);
int /*<<< orphan*/ save_dasm(int /*<<< orphan*/ *);
int /*<<< orphan*/ save_intrp(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void save(const char *fname) {
  char buf[4096];
  FILE *f;
  sprintf(buf, "Error opening %s for writing\n", fname);
  f = fopen(fname, "w");
  if (!f) {
    perror(buf);
    exit(1);
  }
  compute_cache_ids();
  save_dasm(f);
  save_intrp(f);
  save_cdec(f);
  save_cintrp(f);
  fclose(f);
}


x86 assembly (clang, -O0):
<save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    1201 <save+0x61>
lea    -0x1010(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1050 <compute_cache_ids@plt>
mov    -0x1018(%rbp),%rdi
call   1070 <save_dasm@plt>
mov    -0x1018(%rbp),%rdi
call   10c0 <save_intrp@plt>
mov    -0x1018(%rbp),%rdi
call   1040 <save_cdec@plt>
mov    -0x1018(%rbp),%rdi
call   1060 <save_cintrp@plt>
mov    -0x1018(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save>:
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%rbx
lea    0xe4e(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     120b <save+0x6b>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <compute_cache_ids@plt>
mov    %rbx,%rdi
call   1070 <save_dasm@plt>
mov    %rbx,%rdi
call   10c0 <save_intrp@plt>
mov    %rbx,%rdi
call   1040 <save_cdec@plt>
mov    %rbx,%rdi
call   1060 <save_cintrp@plt>
mov    %rbx,%rdi
add    $0x1000,%rsp
pop    %rbx
jmp    1030 <fclose@plt>
mov    %rsp,%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Error opening %s for writing\0A\00"
@.str.1 = [2 x i8] c"w\00"
define void @save(i8* %0) {
%2 = alloca i8*
%3 = alloca [4096 x i8]
%4 = alloca i32*
store i8* %0, i8** %2
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%14 = call i32 @perror(i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = call i32 (...) @compute_cache_ids()
%18 = load i32*, i32** %4
%19 = call i32 @save_dasm(i32* %18)
%20 = load i32*, i32** %4
%21 = call i32 @save_intrp(i32* %20)
%22 = load i32*, i32** %4
%23 = call i32 @save_cdec(i32* %22)
%24 = load i32*, i32** %4
%25 = call i32 @save_cintrp(i32* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Error opening %s for writing\0A\00"
@.str.1 = [2 x i8] c"w\00"
define void @save(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @perror(i8* %3)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = tail call i32 (...) @compute_cache_ids()
%12 = tail call i32 @save_dasm(i32* %5)
%13 = tail call i32 @save_intrp(i32* %5)
%14 = tail call i32 @save_cdec(i32* %5)
%15 = tail call i32 @save_cintrp(i32* %5)
%16 = tail call i32 @fclose(i32* %5)
ret void
}