#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 */
char *malloc(size_t);
char *realloc(char *, size_t);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *levelup(char *cur, const char *next) {
  size_t len;
  if (cur == NULL) {
    len = strlen(next) + 1;
    cur = malloc(len);
    if (cur == NULL)
      return NULL;
    strcpy(cur, next);
  } else {
    len = strlen(cur) + strlen(next) + 2;
    cur = realloc(cur, len);
    if (cur == NULL)
      return NULL;
    strcat(cur, ".");
    strcat(cur, next);
  }
  return cur;
}


x86 assembly (clang, -O0):
<levelup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <levelup+0x64>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a2 <levelup+0x52>
movq   $0x0,-0x8(%rbp)
jmp    1227 <levelup+0xd7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    121f <levelup+0xcf>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1202 <levelup+0xb2>
movq   $0x0,-0x8(%rbp)
jmp    1227 <levelup+0xd7>
mov    -0x10(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<levelup>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11a5 <levelup+0x55>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r15d,%eax
add    $0x2,%eax
movslq %eax,%rsi
mov    %rbx,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     11cd <levelup+0x7d>
mov    %rax,%rbx
lea    0xe70(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
jmp    11cf <levelup+0x7f>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     11cd <levelup+0x7d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    11cf <levelup+0x7f>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @levelup(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %9
store i8* null, i8** %3
br label %45
19: ; preds = %9
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 @strcpy(i8* %20, i8* %21)
br label %43
23: ; preds = %2
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %25, %27
%29 = add nsw i32 %28, 2
%30 = sext i32 %29 to i64
store i64 %30, i64* %6
%31 = load i8*, i8** %4
%32 = load i64, i64* %6
%33 = call i8* @realloc(i8* %31, i64 %32)
store i8* %33, i8** %4
%34 = load i8*, i8** %4
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %23
store i8* null, i8** %3
br label %45
37: ; preds = %23
%38 = load i8*, i8** %4
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%40 = load i8*, i8** %4
%41 = load i8*, i8** %5
%42 = call i32 @strcat(i8* %40, i8* %41)
br label %43
43: ; preds = %37, %19
%44 = load i8*, i8** %4
store i8* %44, i8** %3
br label %45
45: ; preds = %43, %36, %18
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @levelup(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %1)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = tail call i8* @malloc(i64 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %23, label %10
10: ; preds = %4
%11 = tail call i32 @strcpy(i8* %8, i8* %1)
br label %23
12: ; preds = %2
%13 = tail call i32 @strlen(i8* %0)
%14 = tail call i32 @strlen(i8* %1)
%15 = add i32 %13, 2
%16 = add i32 %15, %14
%17 = sext i32 %16 to i64
%18 = tail call i8* @realloc(i8* %0, i64 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %12
%21 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @strcat(i8* %18, i8* %1)
br label %23
23: ; preds = %10, %20, %12, %4
%24 = phi i8* [ null, %4 ], [ null, %12 ], [ %8, %10 ], [ %18, %20 ]
ret i8* %24
}