#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ itoa(int, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void generate_filename(int wknum, char *filename) {
  char *wknumchar;
  wknumchar = (char *)malloc(sizeof(char) * 2);
  if (!wknumchar) {
    printf("Error allocating memory...\n");
    exit(EXIT_FAILURE);
  }
  itoa(wknum, wknumchar, 10);
  strcpy(filename, "MyPlan");
  strcat(filename, wknumchar);
  strcat(filename, ".txt");
}


x86 assembly (clang, -O0):
<generate_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <generate_filename+0x42>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1080 <itoa@plt>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_filename>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x2,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b7 <generate_filename+0x57>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0xa,%edx
call   1080 <itoa@plt>
lea    0xe6f(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <strcat@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Error allocating memory...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"MyPlan\00"
@.str.2 = [5 x i8] c".txt\00"
define void @generate_filename(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i64 @malloc(i32 2)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = load i32, i32* %3
%16 = load i8*, i8** %5
%17 = call i32 @itoa(i32 %15, i8* %16, i32 10)
%18 = load i8*, i8** %4
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* %20, i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.1 = [7 x i8] c"MyPlan\00"
@.str.2 = [5 x i8] c".txt\00"
@str = [27 x i8] c"Error allocating memory...\00"
define void @generate_filename(i32 %0, i8* %1) {
%3 = tail call i64 @malloc(i32 2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = tail call i32 @itoa(i32 %0, i8* %4, i32 10)
%12 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @strcat(i8* %1, i8* %4)
%14 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret void
}