#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 *C_mkAssign(char *, char *);
char *C_mkIndexName(char *);
char *C_mkOneLineComments(char *);
char *UTIL_mallocStr(size_t);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *C_mkIndex(char *name, char *indexNum, char *comments) {
  char *commentText = (comments) ? C_mkOneLineComments(comments) : NULL;
  char *varName = C_mkIndexName(name);
  char *assign = C_mkAssign(varName, indexNum);
  size_t length = ((commentText) ? strlen(commentText) + strlen("    ") : 0) +
                  strlen(assign) + strlen("    ") + 5;
  char *index = UTIL_mallocStr(length);
  free(varName);
  strcpy(index, "    ");
  if (commentText) {
    strcat(index, commentText);
    strcat(index, "\n");
    strcat(index, "    ");
    free(commentText);
  }
  strcat(index, assign);
  free(assign);
  return index;
}


x86 assembly (clang, -O0):
<C_mkIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <C_mkIndex+0x31>
mov    -0x18(%rbp),%rdi
call   1080 <C_mkOneLineComments@plt>
mov    %rax,-0x48(%rbp)
jmp    11bc <C_mkIndex+0x3c>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    11bc <C_mkIndex+0x3c>
mov    -0x48(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <C_mkIndexName@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <C_mkAssign@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1214 <C_mkIndex+0x94>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x50(%rbp)
lea    0xe00(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4c(%rbp)
jmp    121e <C_mkIndex+0x9e>
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
jmp    121e <C_mkIndex+0x9e>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
lea    0xdc2(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
add    $0x5,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1090 <UTIL_mallocStr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     12ba <C_mkIndex+0x13a>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<C_mkIndex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdx,%rdx
je     11a3 <C_mkIndex+0x23>
mov    %rdx,%rdi
call   1080 <C_mkOneLineComments@plt>
mov    %rax,%r12
jmp    11a6 <C_mkIndex+0x26>
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1070 <C_mkIndexName@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <C_mkAssign@plt>
mov    %rax,%r14
test   %r12,%r12
je     11e2 <C_mkIndex+0x62>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xe2b(%rip),%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbx,1),%ebp
add    $0x5,%ebp
jmp    11e7 <C_mkIndex+0x67>
mov    $0x5,%ebp
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xe08(%rip),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
add    %ebp,%ebx
add    %eax,%ebx
movslq %ebx,%rdi
call   1090 <UTIL_mallocStr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
test   %r12,%r12
je     1258 <C_mkIndex+0xd8>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <strcat@plt>
lea    0xdcc(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <strcat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
define i8* @C_mkIndex(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i8* @C_mkOneLineComments(i8* %2)
br label %7
7: ; preds = %3, %5
%8 = phi i8* [ %6, %5 ], [ null, %3 ]
%9 = tail call i8* @C_mkIndexName(i8* %0)
%10 = tail call i8* @C_mkAssign(i8* %9, i8* %1)
%11 = icmp eq i8* %8, null
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = tail call i32 @strlen(i8* %8)
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %14, %13
%16 = add i32 %15, 5
br label %17
17: ; preds = %7, %12
%18 = phi i32 [ %16, %12 ], [ 5, %7 ]
%19 = tail call i32 @strlen(i8* %10)
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = add i32 %18, %19
%22 = add i32 %21, %20
%23 = sext i32 %22 to i64
%24 = tail call i8* @UTIL_mallocStr(i64 %23)
%25 = tail call i32 @free(i8* %9)
%26 = tail call i32 @strcpy(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br i1 %11, label %32, label %27
27: ; preds = %17
%28 = tail call i32 @strcat(i8* %24, i8* %8)
%29 = tail call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = tail call i32 @free(i8* %8)
br label %32
32: ; preds = %27, %17
%33 = tail call i32 @strcat(i8* %24, i8* %10)
%34 = tail call i32 @free(i8* %10)
ret i8* %24
}