#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 */
scalar_t__ checkClasses(char *, char **, char **);
scalar_t__ checkLiterals(char *, char **, char **, int);
char *malloc(int);
char *getTarget(char *reg, char **new, int li) {
  char *target = (char *)malloc(100 * sizeof(char));
  if (checkLiterals(reg, &target, new, li))
    return target;
  if ((*new)[0] != 0) {
    reg = (*new);
  }
  if (checkClasses(reg, &target, new))
    return target;
  *new = &(reg[1]);
  char *temp = malloc(sizeof(char) * 100);
  temp[0] = reg[0];
  temp[1] = 0;
  return temp;
}


x86 assembly (clang, -O0):
<getTarget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x28(%rbp),%rsi
call   1040 <checkLiterals@plt>
cmp    $0x0,%rax
je     117c <getTarget+0x4c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <getTarget+0xcb>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119a <getTarget+0x6a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <checkClasses@plt>
cmp    $0x0,%rax
je     11c2 <getTarget+0x92>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11fb <getTarget+0xcb>
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTarget>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <checkLiterals@plt>
test   %rax,%rax
jne    1185 <getTarget+0x55>
mov    (%r14),%rax
cmpb   $0x0,(%rax)
cmovne %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <checkClasses@plt>
test   %rax,%rax
je     1193 <getTarget+0x63>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x1(%rbx),%rax
mov    %rax,(%r14)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    (%rbx),%cl
mov    %cl,(%rax)
movb   $0x0,0x1(%rax)
jmp    118a <getTarget+0x5a>

LLVM IR (-O0):
define i8* @getTarget(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%10 = call i8* @malloc(i32 100)
store i8* %10, i8** %8
%11 = load i8*, i8** %5
%12 = load i8**, i8*** %6
%13 = load i32, i32* %7
%14 = call i64 @checkLiterals(i8* %11, i8** %8, i8** %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = load i8*, i8** %8
store i8* %17, i8** %4
br label %48
18: ; preds = %3
%19 = load i8**, i8*** %6
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %26
store i8* %27, i8** %5
br label %28
28: ; preds = %25, %18
%29 = load i8*, i8** %5
%30 = load i8**, i8*** %6
%31 = call i64 @checkClasses(i8* %29, i8** %8, i8** %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i8*, i8** %8
store i8* %34, i8** %4
br label %48
35: ; preds = %28
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8**, i8*** %6
store i8* %37, i8** %38
%39 = call i8* @malloc(i32 100)
store i8* %39, i8** %9
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 %42, i8* %44
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i64 1
store i8 0, i8* %46
%47 = load i8*, i8** %9
store i8* %47, i8** %4
br label %48
48: ; preds = %35, %33, %16
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
define i8* @getTarget(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
store i8* %6, i8** %4
%7 = call i64 @checkLiterals(i8* %0, i8** %4, i8** %1, i32 %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = load i8*, i8** %4
br label %25
11: ; preds = %3
%12 = load i8*, i8** %1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
%15 = select i1 %14, i8* %0, i8* %12
%16 = call i64 @checkClasses(i8* %15, i8** %4, i8** %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = load i8*, i8** %4
br label %25
20: ; preds = %11
%21 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %21, i8** %1
%22 = call dereferenceable_or_null(100) i8* @malloc(i32 100)
%23 = load i8, i8* %15
store i8 %23, i8* %22
%24 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %24
br label %25
25: ; preds = %20, %18, %9
%26 = phi i8* [ %10, %9 ], [ %19, %18 ], [ %22, %20 ]
ret i8* %26
}