#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
int strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
char *get_folder_name(char *application_name, char *table_name) {
  char folder_name[512];
  char application_table_name[512];
  if (!application_name || !table_name)
    return "";
  sprintf(application_table_name, "%s_application", application_name);
  if (strcmp(table_name, application_table_name) == 0) {
    strcpy(folder_name, table_name);
  } else if (application_is_primary_application(application_name)) {
    strcpy(folder_name, table_name);
  } else {
    char search_string[512];
    int str_len;
    sprintf(search_string, "%s_", application_name);
    str_len = strlen(search_string);
    if (strncasecmp(table_name, search_string, str_len) != 0) {
      strcpy(folder_name, table_name);
    } else {
      strcpy(folder_name, table_name + strlen(application_name) + 1);
    }
  }
  return strdup(folder_name);
}


x86 assembly (clang, -O0):
<get_folder_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <get_folder_name+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <get_folder_name+0x39>
lea    0xe72(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12cd <get_folder_name+0x15d>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ef <get_folder_name+0x7f>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12bd <get_folder_name+0x14d>
mov    -0x10(%rbp),%rdi
call   1050 <application_is_primary_application@plt>
cmp    $0x0,%rax
je     1217 <get_folder_name+0xa7>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12b8 <get_folder_name+0x148>
lea    -0x620(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xde6(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x620(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x624(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x620(%rbp),%rsi
mov    -0x624(%rbp),%edx
call   1070 <strncasecmp@plt>
cmp    $0x0,%rax
je     1275 <get_folder_name+0x105>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12b3 <get_folder_name+0x143>
lea    -0x220(%rbp),%rax
mov    %rax,-0x630(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x638(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x638(%rbp),%rsi
mov    -0x630(%rbp),%rdi
cltq
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
jmp    12b8 <get_folder_name+0x148>
jmp    12bd <get_folder_name+0x14d>
lea    -0x220(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_folder_name>:
push   %r15
push   %r14
push   %rbx
sub    $0x600,%rsp
lea    0xe8f(%rip),%rax
test   %rdi,%rdi
je     122a <get_folder_name+0xba>
mov    %rsi,%r14
test   %rsi,%rsi
je     122a <get_folder_name+0xba>
mov    %rdi,%rbx
lea    0xe5e(%rip),%rsi
lea    0x400(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1217 <get_folder_name+0xa7>
mov    %rbx,%rdi
call   1050 <application_is_primary_application@plt>
test   %rax,%rax
jne    1217 <get_folder_name+0xa7>
lea    0xe36(%rip),%rsi
lea    0x200(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <strncasecmp@plt>
test   %rax,%rax
jne    1217 <get_folder_name+0xa7>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r14
add    $0x1,%r14
mov    %rsp,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
call   1090 <strdup@plt>
add    $0x600,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [15 x i8] c"%s_application\00"
@.str.2 = [4 x i8] c"%s_\00"
define i8* @get_folder_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12, %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %65
16: ; preds = %12
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %62
28: ; preds = %16
%29 = load i8*, i8** %4
%30 = call i64 @application_is_primary_application(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%34 = load i8*, i8** %5
%35 = call i32 @strcpy(i8* %33, i8* %34)
br label %61
36: ; preds = %28
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = load i8*, i8** %4
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %9
%42 = load i8*, i8** %5
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%44 = load i32, i32* %9
%45 = call i64 @strncasecmp(i8* %42, i8* %43, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %36
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%49 = load i8*, i8** %5
%50 = call i32 @strcpy(i8* %48, i8* %49)
br label %60
51: ; preds = %36
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%53 = load i8*, i8** %5
%54 = load i8*, i8** %4
%55 = call i32 @strlen(i8* %54)
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = call i32 @strcpy(i8* %52, i8* %58)
br label %60
60: ; preds = %51, %47
br label %61
61: ; preds = %60, %32
br label %62
62: ; preds = %61, %24
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%64 = call i8* @strdup(i8* %63)
store i8* %64, i8** %3
br label %65
65: ; preds = %62, %15
%66 = load i8*, i8** %3
ret i8* %66
}

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