#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
char *NewTemporaryVariable(const char *prefix) {
  char *str;
  char *s;
  static int tmpvarnum = 0;
  if (!prefix)
    prefix = "_tmp_";
  s = str = malloc(strlen(prefix) + 16);
  if (!s) {
    fprintf(stderr, "Out of memory!\n");
    exit(1);
  }
  while (*prefix)
    *s++ = *prefix++;
  *s++ = '_';
  sprintf(s, "%04d", tmpvarnum++);
  return str;
}


x86 assembly (clang, -O0):
<NewTemporaryVariable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1172 <NewTemporaryVariable+0x22>
lea    0xe92(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x10,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b9 <NewTemporaryVariable+0x69>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11be <NewTemporaryVariable+0x6e>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f2 <NewTemporaryVariable+0xa2>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11be <NewTemporaryVariable+0x6e>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5f,(%rax)
mov    -0x18(%rbp),%rdi
mov    0x2e3e(%rip),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2e33(%rip)
lea    0xdf6(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NewTemporaryVariable>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
lea    0xea2(%rip),%rbx
cmovne %rdi,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x10(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ce <NewTemporaryVariable+0x7e>
mov    %rax,%r14
mov    (%rbx),%al
mov    %r14,%rdi
test   %al,%al
je     11a1 <NewTemporaryVariable+0x51>
add    $0x1,%rbx
mov    %r14,%rdi
nopl   0x0(%rax,%rax,1)
mov    %al,(%rdi)
add    $0x1,%rdi
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1190 <NewTemporaryVariable+0x40>
movb   $0x5f,(%rdi)
add    $0x1,%rdi
mov    0x2e9e(%rip),%edx
lea    0x1(%rdx),%eax
mov    %eax,0x2e95(%rip)
lea    0xe58(%rip),%rsi
call   1060 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@NewTemporaryVariable.tmpvarnum = internal global i32 0
@.str = [6 x i8] c"_tmp_\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Out of memory!\0A\00"
@.str.2 = [5 x i8] c"%04d\00"
define i8* @NewTemporaryVariable(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %2
br label %8
8: ; preds = %7, %1
%9 = load i8*, i8** %2
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 16
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %3
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %8
br label %20
20: ; preds = %24, %19
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %2
%27 = load i8, i8* %25
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 %27, i8* %28
br label %20
30: ; preds = %20
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
store i8 95, i8* %31
%33 = load i8*, i8** %4
%34 = load i32, i32* @NewTemporaryVariable.tmpvarnum
%35 = add nsw i32 %34, 1
store i32 %35, i32* @NewTemporaryVariable.tmpvarnum
%36 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@NewTemporaryVariable.tmpvarnum = internal unnamed_addr global i32 0
@.str = [6 x i8] c"_tmp_\00"
@stderr = global i32 0
@.str.1 = [16 x i8] c"Out of memory!\0A\00"
@.str.2 = [5 x i8] c"%04d\00"
define noalias i8* @NewTemporaryVariable(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = add nsw i64 %4, 16
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %23, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8, %15
%16 = phi i8 [ %21, %15 ], [ %9, %8 ]
%17 = phi i8* [ %20, %15 ], [ %6, %8 ]
%18 = phi i8* [ %19, %15 ], [ %3, %8 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %16, i8* %17
%21 = load i8, i8* %19
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %15
23: ; preds = %15, %8
%24 = phi i8* [ %6, %8 ], [ %20, %15 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8 95, i8* %24
%26 = load i32, i32* @NewTemporaryVariable.tmpvarnum
%27 = add nsw i32 %26, 1
store i32 %27, i32* @NewTemporaryVariable.tmpvarnum
%28 = tail call i32 @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
ret i8* %6
}