#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
char *appaserver_link_get_tail_half(char *application_name, char *filename_stem,
                                    char *begin_date_string,
                                    char *end_date_string, pid_t process_id,
                                    char *session, char *extension) {
  static char tail_half[512];
  char application_part[128];
  char date_part[128];
  char key_part[128];
  *date_part = '\0';
  if (begin_date_string && *begin_date_string) {
    sprintf(date_part, "_%s", begin_date_string);
  }
  if (end_date_string && *end_date_string) {
    sprintf(date_part + strlen(date_part), "_%s", end_date_string);
  }
  if (session && *session) {
    sprintf(key_part, "_%s", session);
  } else if (process_id) {
    sprintf(key_part, "_%d", process_id);
  } else {
    *key_part = '\0';
  }
  *application_part = '\0';
  if (application_name) {
    sprintf(application_part, "/%s/%s/%s/", "appaserver", application_name,
            "data");
  }
  sprintf(tail_half, "%s%s%s%s.%s", application_part, filename_stem,
          (*date_part) ? date_part : "", key_part,
          (extension) ? extension : "null");
  return tail_half;
}


x86 assembly (clang, -O0):
<appaserver_link_get_tail_half>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f0,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movb   $0x0,-0x130(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1182 <appaserver_link_get_tail_half+0x62>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1182 <appaserver_link_get_tail_half+0x62>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
cmpq   $0x0,-0x20(%rbp)
je     11d5 <appaserver_link_get_tail_half+0xb5>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d5 <appaserver_link_get_tail_half+0xb5>
lea    -0x130(%rbp),%rax
mov    %rax,-0x1b8(%rbp)
lea    -0x130(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1b8(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
cmpq   $0x0,-0x30(%rbp)
je     120e <appaserver_link_get_tail_half+0xee>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     120e <appaserver_link_get_tail_half+0xee>
lea    -0x1b0(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1241 <appaserver_link_get_tail_half+0x121>
cmpl   $0x0,-0x24(%rbp)
je     1235 <appaserver_link_get_tail_half+0x115>
lea    -0x1b0(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    123c <appaserver_link_get_tail_half+0x11c>
movb   $0x0,-0x1b0(%rbp)
jmp    1241 <appaserver_link_get_tail_half+0x121>
movb   $0x0,-0xb0(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     127a <appaserver_link_get_tail_half+0x15a>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    0xda3(%rip),%rsi
lea    0xda7(%rip),%rdx
lea    0xdab(%rip),%r8
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0x1c8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1c0(%rbp)
movsbl -0x130(%rbp),%eax
cmp    $0x0,%eax
je     12b6 <appaserver_link_get_tail_half+0x196>
lea    -0x130(%rbp),%rax
mov    %rax,-0x1d0(%rbp)
jmp    12c9 <appaserver_link_get_tail_half+0x1a9>
lea    0xd55(%rip),%rax
mov    %rax,-0x1d0(%rbp)
jmp    12c9 <appaserver_link_get_tail_half+0x1a9>
mov    -0x1d0(%rbp),%rax
mov    %rax,-0x1e0(%rbp)
lea    -0x1b0(%rbp),%rax
mov    %rax,-0x1d8(%rbp)
cmpq   $0x0,0x10(%rbp)
je     1300 <appaserver_link_get_tail_half+0x1e0>
mov    0x10(%rbp),%rax
mov    %rax,-0x1e8(%rbp)
jmp    1313 <appaserver_link_get_tail_half+0x1f3>
lea    0xd28(%rip),%rax
mov    %rax,-0x1e8(%rbp)
jmp    1313 <appaserver_link_get_tail_half+0x1f3>
mov    -0x1d8(%rbp),%r9
mov    -0x1e0(%rbp),%r8
mov    -0x1c0(%rbp),%rcx
mov    -0x1c8(%rbp),%rdx
mov    -0x1e8(%rbp),%rax
lea    0x2d03(%rip),%rdi
lea    0xcdf(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2cea(%rip),%rax
add    $0x1f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appaserver_link_get_tail_half>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x190,%rsp
mov    %r9,%rbx
mov    %r8d,%r12d
mov    %rcx,%rbp
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,0x10(%rsp)
test   %rdx,%rdx
je     1160 <appaserver_link_get_tail_half+0x40>
cmpb   $0x0,(%rdx)
je     1160 <appaserver_link_get_tail_half+0x40>
lea    0xeac(%rip),%rsi
lea    0x10(%rsp),%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
test   %rbp,%rbp
je     1190 <appaserver_link_get_tail_half+0x70>
cmpb   $0x0,0x0(%rbp)
je     1190 <appaserver_link_get_tail_half+0x70>
lea    0x10(%rsp),%rdi
call   1030 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
lea    0xe7a(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
test   %rbx,%rbx
je     11b5 <appaserver_link_get_tail_half+0x95>
cmpb   $0x0,(%rbx)
je     11b5 <appaserver_link_get_tail_half+0x95>
lea    0xe5f(%rip),%rsi
lea    0x90(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    11dd <appaserver_link_get_tail_half+0xbd>
test   %r12d,%r12d
je     11d5 <appaserver_link_get_tail_half+0xb5>
lea    0xe43(%rip),%rsi
lea    0x90(%rsp),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    11dd <appaserver_link_get_tail_half+0xbd>
movb   $0x0,0x90(%rsp)
mov    0x1c0(%rsp),%rbx
movb   $0x0,0x110(%rsp)
test   %r15,%r15
je     1219 <appaserver_link_get_tail_half+0xf9>
lea    0xe0f(%rip),%rsi
lea    0xe13(%rip),%rdx
lea    0xe17(%rip),%r8
lea    0x110(%rsp),%rdi
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
cmpb   $0x0,0x10(%rsp)
lea    0xded(%rip),%rax
lea    0x10(%rsp),%r8
cmove  %rax,%r8
test   %rbx,%rbx
lea    0xdf7(%rip),%rax
cmovne %rbx,%rax
mov    %rax,(%rsp)
lea    0x2df9(%rip),%rbx
lea    0xdd5(%rip),%rsi
lea    0x110(%rsp),%rdx
lea    0x90(%rsp),%r9
mov    %rbx,%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x190,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@appaserver_link_get_tail_half.tail_half = internal global [512 x i8] zeroinitializer
@.str = [4 x i8] c"_%s\00"
@.str.1 = [4 x i8] c"_%d\00"
@.str.2 = [11 x i8] c"/%s/%s/%s/\00"
@.str.3 = [11 x i8] c"appaserver\00"
@.str.4 = [5 x i8] c"data\00"
@.str.5 = [12 x i8] c"%s%s%s%s.%s\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [5 x i8] c"null\00"
define i8* @appaserver_link_get_tail_half(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [128 x i8]
%16 = alloca [128 x i8]
%17 = alloca [128 x i8]
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
store i8 0, i8* %18
%19 = load i8*, i8** %10
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %30
21: ; preds = %7
%22 = load i8*, i8** %10
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%28 = load i8*, i8** %10
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %26, %21, %7
%31 = load i8*, i8** %11
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i8*, i8** %11
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
%44 = load i8*, i8** %11
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %38, %33, %30
%47 = load i8*, i8** %13
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %58
49: ; preds = %46
%50 = load i8*, i8** %13
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%56 = load i8*, i8** %13
%57 = call i32 (i8*, i8*, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %56)
br label %68
58: ; preds = %49, %46
%59 = load i32, i32* %12
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%63 = load i32, i32* %12
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %63)
br label %67
65: ; preds = %58
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
store i8 0, i8* %66
br label %67
67: ; preds = %65, %61
br label %68
68: ; preds = %67, %54
%69 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
store i8 0, i8* %69
%70 = load i8*, i8** %8
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%74 = load i8*, i8** %8
%75 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %76
76: ; preds = %72, %68
%77 = getelementptr inbounds [128 x i8], [128 x i8]* %15, i64 0, i64 0
%78 = load i8*, i8** %9
%79 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %76
%84 = getelementptr inbounds [128 x i8], [128 x i8]* %16, i64 0, i64 0
br label %86
85: ; preds = %76
br label %86
86: ; preds = %85, %83
%87 = phi i8* [ %84, %83 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %85 ]
%88 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%89 = load i8*, i8** %14
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %93
91: ; preds = %86
%92 = load i8*, i8** %14
br label %94
93: ; preds = %86
br label %94
94: ; preds = %93, %91
%95 = phi i8* [ %92, %91 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), %93 ]
%96 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @appaserver_link_get_tail_half.tail_half, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %77, i8* %78, i8* %87, i8* %88, i8* %95)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @appaserver_link_get_tail_half.tail_half, i64 0, i64 0)
}

LLVM IR (-O2):
@appaserver_link_get_tail_half.tail_half = internal global [512 x i8] zeroinitializer
@.str = [4 x i8] c"_%s\00"
@.str.1 = [4 x i8] c"_%d\00"
@.str.2 = [11 x i8] c"/%s/%s/%s/\00"
@.str.3 = [11 x i8] c"appaserver\00"
@.str.4 = [5 x i8] c"data\00"
@.str.5 = [12 x i8] c"%s%s%s%s.%s\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [5 x i8] c"null\00"
define i8* @appaserver_link_get_tail_half(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5, i8* %6) {
%8 = alloca [128 x i8]
%9 = alloca [128 x i8]
%10 = alloca [128 x i8]
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
store i8 0, i8* %12
%14 = icmp eq i8* %2, null
br i1 %14, label %20, label %15
15: ; preds = %7
%16 = load i8, i8* %2
%17 = icmp eq i8 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %20
20: ; preds = %18, %15, %7
%21 = icmp eq i8* %3, null
br i1 %21, label %30, label %22
22: ; preds = %20
%23 = load i8, i8* %3
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i32 @strlen(i8* %12)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 %27
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %30
30: ; preds = %25, %22, %20
%31 = icmp eq i8* %5, null
br i1 %31, label %37, label %32
32: ; preds = %30
%33 = load i8, i8* %5
%34 = icmp eq i8 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %42
37: ; preds = %32, %30
%38 = icmp eq i32 %4, 0
br i1 %38, label %41, label %39
39: ; preds = %37
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %42
41: ; preds = %37
store i8 0, i8* %13
br label %42
42: ; preds = %39, %41, %35
store i8 0, i8* %11
%43 = icmp eq i8* %0, null
br i1 %43, label %46, label %44
44: ; preds = %42
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = load i8, i8* %12
%48 = icmp eq i8 %47, 0
%49 = select i1 %48, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8* %12
%50 = icmp eq i8* %6, null
%51 = select i1 %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %6
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([512 x i8], [512 x i8]* @appaserver_link_get_tail_half.tail_half, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %11, i8* %1, i8* %49, i8* %13, i8* %51)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @appaserver_link_get_tail_half.tail_half, i64 0, i64 0)
}