#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void save(const char *contents, int i) {
  char filepath[80];
  sprintf(filepath, "input_%d.txt", i);
  FILE *fp = fopen(filepath, "ab");
  if (fp != NULL) {
    fputs(contents, fp);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xea3(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1197 <save+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %esi,%edx
mov    %rdi,%r14
lea    0xead(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     118f <save+0x4f>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"input_%d.txt\00"
@.str.1 = [3 x i8] c"ab\00"
define void @save(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = load i32, i32* %4
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32*, i32** %6
%17 = call i32 @fputs(i8* %15, i32* %16)
%18 = load i32*, i32** %6
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %14, %2
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"input_%d.txt\00"
@.str.1 = [3 x i8] c"ab\00"
define void @save(i8* nocapture %0, i32 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @fputs(i8* %0, i32* %6)
%10 = tail call i32 @fclose(i32* %6)
br label %11
11: ; preds = %8, %2
ret void
}