#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*/ error(char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
void createnewgenfile(int gen) {
  char t[100];
  sprintf(t, "GEN-%04d", gen);
  FILE *g = fopen(t, "wb");
  if (!g)
    error("couldn't create current generation file");
  if (fclose(g))
    error("error on creating current generation file");
}


x86 assembly (clang, -O0):
<createnewgenfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea4(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    118c <createnewgenfile+0x4c>
lea    0xe85(%rip),%rdi
call   1040 <error@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11ab <createnewgenfile+0x6b>
lea    0xe8e(%rip),%rdi
call   1040 <error@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createnewgenfile>:
push   %rbx
sub    $0x70,%rsp
mov    %edi,%edx
lea    0xeb2(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117c <createnewgenfile+0x3c>
lea    0xe95(%rip),%rdi
call   1040 <error@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     119a <createnewgenfile+0x5a>
lea    0xea4(%rip),%rdi
add    $0x70,%rsp
pop    %rbx
jmp    1040 <error@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"GEN-%04d\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [40 x i8] c"couldn't create current generation file\00"
@.str.3 = [42 x i8] c"error on creating current generation file\00"
define void @createnewgenfile(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32*
store i32 %0, i32* %2
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* %2
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 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 %14, label %12
12: ; preds = %1
%13 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i32*, i32** %4
%16 = call i64 @fclose(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"GEN-%04d\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [40 x i8] c"couldn't create current generation file\00"
@.str.3 = [42 x i8] c"error on creating current generation file\00"
define void @createnewgenfile(i32 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = tail call i64 @fclose(i32* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
ret void
}