#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*/ fprintf(int /*<<< orphan*/ *, char *, char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void newfile(int userid) {
  FILE *fp;
  char a[10];
  int x = 0;
  sprintf(a, "save%d.sav", userid);
  fp = fopen(a, "w");
  fprintf(fp, "%s %d %d\n", a, x, x);
  fclose(fp);
}


x86 assembly (clang, -O0):
<newfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea0(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x1a(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1a(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe7e(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newfile>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%edx
lea    0xeb0(%rip),%rsi
lea    0xe(%rsp),%r14
mov    %r14,%rdi
call   1060 <sprintf@plt>
lea    0xea7(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xe97(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"save%d.sav\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c"%s %d %d\0A\00"
define void @newfile(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [10 x i8]
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %13, i32 %14)
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"save%d.sav\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [10 x i8] c"%s %d %d\0A\00"
define void @newfile(i32 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 0, i32 0)
%7 = call i32 @fclose(i32* %5)
ret void
}