#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*/ asprintf(char **, char *, char const *, ...);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
FILE *get_file_pointer(const char *header, int ix) {
  char *fname;
  FILE *f;
  if (ix >= 0)
    asprintf(&fname, "debug_%s_%02d", header, ix);
  else
    asprintf(&fname, "debug_%s", header);
  f = fopen(fname, "w");
  if (!f)
    perror(fname);
  free(fname);
  return f;
}


x86 assembly (clang, -O0):
<get_file_pointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1177 <get_file_pointer+0x37>
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
jmp    118d <get_file_pointer+0x4d>
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <get_file_pointer+0x75>
mov    -0x18(%rbp),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_pointer>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rdx
test   %esi,%esi
js     1163 <get_file_pointer+0x23>
mov    %esi,%ecx
lea    0xeab(%rip),%rsi
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1040 <asprintf@plt>
jmp    1176 <get_file_pointer+0x36>
lea    0xea4(%rip),%rsi
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1040 <asprintf@plt>
mov    0x8(%rsp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a2 <get_file_pointer+0x62>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%rdi
call   1060 <perror@plt>
jmp    118f <get_file_pointer+0x4f>

LLVM IR (-O0):
@.str = [14 x i8] c"debug_%s_%02d\00"
@.str.1 = [9 x i8] c"debug_%s\00"
@.str.2 = [2 x i8] c"w\00"
define i32* @get_file_pointer(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
br label %16
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %9
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = call i32 @perror(i8* %22)
br label %24
24: ; preds = %21, %16
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i32*, i32** %6
ret i32* %27
}

LLVM IR (-O2):
@.str = [14 x i8] c"debug_%s_%02d\00"
@.str.1 = [9 x i8] c"debug_%s\00"
@.str.2 = [2 x i8] c"w\00"
define noalias i32* @get_file_pointer(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp sgt i32 %1, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
br label %10
8: ; preds = %2
%9 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %8, %6
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i32 @perror(i8* %15)
br label %17
17: ; preds = %14, %10
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
ret i32* %12
}