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

/* Variables and functions */
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *tempString(char *str) {
  int size;
  static char buf[2000];
  static int ptr;
  size = strlen(str) + 1;
  if (ptr < size)
    ptr = sizeof(buf);
  ptr -= size;
  if (!(ptr >= 0))
    *(volatile long *)-1 = 0;
  strcpy(buf + ptr, str);
  return buf + ptr;
}


x86 assembly (clang, -O0):
<tempString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    0x36cf(%rip),%eax
cmp    -0xc(%rbp),%eax
jge    1154 <tempString+0x34>
movl   $0x7d0,0x36bc(%rip)
mov    -0xc(%rbp),%ecx
mov    0x36b3(%rip),%eax
sub    %ecx,%eax
mov    %eax,0x36ab(%rip)
cmpl   $0x0,0x36a4(%rip)
jge    1180 <tempString+0x60>
mov    $0xffffffffffffffff,%rax
movq   $0x0,(%rax)
movslq 0x3689(%rip),%rax
lea    0x2eb2(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movslq 0x366f(%rip),%rcx
lea    0x2e98(%rip),%rax
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tempString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    0x36de(%rip),%edx
cmp    %eax,%edx
not    %eax
mov    $0x7d0,%ecx
cmovg  %edx,%ecx
add    %eax,%ecx
mov    %ecx,0x36ca(%rip)
jns    1154 <tempString+0x34>
movq   $0x0,0xffffffffffffffff
movslq %ecx,%rdi
lea    0x2ee2(%rip),%r14
add    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movslq 0x36a0(%rip),%rax
add    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@tempString.buf = internal global [2000 x i8] zeroinitializer
@tempString.ptr = internal global i32 0
define i8* @tempString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, 1
store i32 %6, i32* %3
%7 = load i32, i32* @tempString.ptr
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 2000, i32* @tempString.ptr
br label %11
11: ; preds = %10, %1
%12 = load i32, i32* %3
%13 = load i32, i32* @tempString.ptr
%14 = sub nsw i32 %13, %12
store i32 %14, i32* @tempString.ptr
%15 = load i32, i32* @tempString.ptr
%16 = icmp sge i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %11
store volatile i64 0, i64* inttoptr (i64 -1 to i64*)
br label %18
18: ; preds = %17, %11
%19 = load i32, i32* @tempString.ptr
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* getelementptr inbounds ([2000 x i8], [2000 x i8]* @tempString.buf, i64 0, i64 0), i64 %20
%22 = load i8*, i8** %2
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i32, i32* @tempString.ptr
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* getelementptr inbounds ([2000 x i8], [2000 x i8]* @tempString.buf, i64 0, i64 0), i64 %25
ret i8* %26
}

LLVM IR (-O2):
@tempString.buf = internal global [2000 x i8] zeroinitializer
@tempString.ptr = internal unnamed_addr global i32 0
define i8* @tempString(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = xor i32 %2, -1
%4 = load i32, i32* @tempString.ptr
%5 = icmp sgt i32 %4, %2
%6 = select i1 %5, i32 %4, i32 2000
%7 = add i32 %6, %3
store i32 %7, i32* @tempString.ptr
%8 = icmp sgt i32 %7, -1
br i1 %8, label %10, label %9
9: ; preds = %1
store volatile i64 0, i64* inttoptr (i64 -1 to i64*)
br label %10
10: ; preds = %9, %1
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds [2000 x i8], [2000 x i8]* @tempString.buf, i64 0, i64 %11
%13 = tail call i32 @strcpy(i8* %12, i8* %0)
%14 = load i32, i32* @tempString.ptr
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [2000 x i8], [2000 x i8]* @tempString.buf, i64 0, i64 %15
ret i8* %16
}