#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 PATH_MAX;
int /*<<< orphan*/ *fopen(char *, char const *);
int /*<<< orphan*/ get_storage_path(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
FILE *get_persistent_storage(const char *tag, const char *mode) {
  char buf[PATH_MAX];
  char path[PATH_MAX];
  get_storage_path(buf);
  snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
  path[PATH_MAX - 1] = '\0';
  return fopen(path, mode);
}


x86 assembly (clang, -O0):
<get_persistent_storage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
call   1030 <get_storage_path@plt>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x8(%rbp),%r8
lea    0xe52(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
mov    -0x10(%rbp),%rsi
call   1050 <fopen@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_persistent_storage>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2ea5(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
call   1030 <get_storage_path@plt>
mov    0x0(%r13),%esi
add    $0xffffffff,%esi
lea    0xe81(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %r15,%r8
call   1040 <snprintf@plt>
movslq 0x0(%r13),%rax
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s_%s\00"
define i32* @get_persistent_storage(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* @PATH_MAX
%13 = zext i32 %12 to i64
%14 = alloca i8, i64 %13
store i64 %13, i64* %7
%15 = call i32 @get_storage_path(i8* %11)
%16 = load i32, i32* @PATH_MAX
%17 = sub nsw i32 %16, 1
%18 = load i8*, i8** %3
%19 = call i32 @snprintf(i8* %14, i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %18)
%20 = load i32, i32* @PATH_MAX
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %14, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %4
%25 = call i32* @fopen(i8* %14, i8* %24)
%26 = load i8*, i8** %5
ret i32* %25
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s_%s\00"
define noalias i32* @get_persistent_storage(i8* %0, i8* nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = call i32 @get_storage_path(i8* %5)
%8 = load i32, i32* @PATH_MAX
%9 = add nsw i32 %8, -1
%10 = call i32 @snprintf(i8* %6, i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %0)
%11 = load i32, i32* @PATH_MAX
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %6, i64 %13
store i8 0, i8* %14
%15 = call i32* @fopen(i8* %6, i8* %1)
ret i32* %15
}