#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__ application_is_primary_application(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
char *get_table_name(char *application_name, char *folder_name) {
  char table_name[512];
  if (!application_name)
    return folder_name;
  if (strcmp(folder_name, "application") == 0) {
    sprintf(table_name, "%s_%s", application_name, folder_name);
  } else if (application_is_primary_application(application_name)) {
    sprintf(table_name, "%s", folder_name);
  } else {
    sprintf(table_name, "%s_%s", application_name, folder_name);
  }
  return strdup(table_name);
}


x86 assembly (clang, -O0):
<get_table_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116b <get_table_name+0x2b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    120a <get_table_name+0xca>
mov    -0x18(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11a7 <get_table_name+0x67>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11fa <get_table_name+0xba>
mov    -0x10(%rbp),%rdi
call   1030 <application_is_primary_application@plt>
cmp    $0x0,%rax
je     11d8 <get_table_name+0x98>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11f5 <get_table_name+0xb5>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11fa <get_table_name+0xba>
lea    -0x220(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_table_name>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
test   %rdi,%rdi
je     11b5 <get_table_name+0x65>
mov    %rdi,%r14
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1193 <get_table_name+0x43>
mov    %r14,%rdi
call   1040 <application_is_primary_application@plt>
test   %rax,%rax
je     1193 <get_table_name+0x43>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
jmp    11aa <get_table_name+0x5a>
lea    0xe72(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rsp,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"application\00"
@.str.1 = [6 x i8] c"%s_%s\00"
@.str.2 = [3 x i8] c"%s\00"
define i8* @get_table_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = load i8*, i8** %5
store i8* %10, i8** %3
br label %37
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %18)
br label %34
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = call i64 @application_is_primary_application(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %33
28: ; preds = %20
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
br label %33
33: ; preds = %28, %24
br label %34
34: ; preds = %33, %15
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %3
br label %37
37: ; preds = %34, %9
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
@.str = [12 x i8] c"application\00"
@.str.1 = [6 x i8] c"%s_%s\00"
define i8* @get_table_name(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %18
11: ; preds = %6
%12 = tail call i64 @application_is_primary_application(i8* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i8* @strcpy(i8* %4, i8* dereferenceable(1) %1)
br label %18
16: ; preds = %11
%17 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %18
18: ; preds = %14, %16, %9
%19 = call i8* @strdup(i8* %4)
br label %20
20: ; preds = %2, %18
%21 = phi i8* [ %19, %18 ], [ %1, %2 ]
ret i8* %21
}