#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 */
int /*<<< orphan*/ assert(int);
char *calloc(int, int);
scalar_t__ is_unknown(char);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
char *format_allele_index(char base, char reference_base, char *alt_bases) {
  int length_of_alt_bases = strlen(alt_bases);
  assert(length_of_alt_bases < 100);
  char *result = calloc(5, sizeof(char));
  int index;
  if (is_unknown(base)) {
    base = '*';
  }
  if (reference_base == base) {
    sprintf(result, "0");
  } else {
    sprintf(result, ".");
    for (index = 1; index <= length_of_alt_bases; index++) {
      if (alt_bases[index - 1] == base) {
        sprintf(result, "%i", index);
        break;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<format_allele_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    $0x5,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <is_unknown@plt>
cmp    $0x0,%rax
je     11af <format_allele_index+0x5f>
movb   $0x2a,-0x1(%rbp)
movsbl -0x2(%rbp),%eax
movsbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jne    11d6 <format_allele_index+0x86>
mov    -0x20(%rbp),%rdi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    124a <format_allele_index+0xfa>
mov    -0x20(%rbp),%rdi
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1245 <format_allele_index+0xf5>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jne    1232 <format_allele_index+0xe2>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1245 <format_allele_index+0xf5>
jmp    1237 <format_allele_index+0xe7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ef <format_allele_index+0x9f>
jmp    124a <format_allele_index+0xfa>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_allele_index>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%ebp
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0x64,%eax
setl   %dil
call   1060 <assert@plt>
mov    $0x5,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1030 <is_unknown@plt>
test   %rax,%rax
mov    $0x2a,%eax
cmove  %ebp,%eax
cmp    %r12b,%al
jne    11a9 <format_allele_index+0x59>
movw   $0x30,(%r14)
jmp    11e3 <format_allele_index+0x93>
movw   $0x2e,(%r14)
test   %ebx,%ebx
jle    11e3 <format_allele_index+0x93>
add    $0x1,%ebx
mov    $0x1,%edx
nopl   0x0(%rax,%rax,1)
cmp    %al,-0x1(%r15,%rdx,1)
je     11d2 <format_allele_index+0x82>
add    $0x1,%rdx
cmp    %rdx,%rbx
jne    11c0 <format_allele_index+0x70>
jmp    11e3 <format_allele_index+0x93>
lea    0xe27(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"%i\00"
define i8* @format_allele_index(i8 signext %0, i8 signext %1, i8* %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 100
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i8* @calloc(i32 5, i32 1)
store i8* %16, i8** %8
%17 = load i8, i8* %4
%18 = call i64 @is_unknown(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %3
store i8 42, i8* %4
br label %21
21: ; preds = %20, %3
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %23, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i8*, i8** %8
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %57
30: ; preds = %21
%31 = load i8*, i8** %8
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %9
br label %33
33: ; preds = %53, %30
%34 = load i32, i32* %9
%35 = load i32, i32* %7
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %56
37: ; preds = %33
%38 = load i8*, i8** %6
%39 = load i32, i32* %9
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = load i8, i8* %4
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %44, %46
br i1 %47, label %48, label %52
48: ; preds = %37
%49 = load i8*, i8** %8
%50 = load i32, i32* %9
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %50)
br label %56
52: ; preds = %37
br label %53
53: ; preds = %52
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %33
56: ; preds = %48, %33
br label %57
57: ; preds = %56, %27
%58 = load i8*, i8** %8
ret i8* %58
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%i\00"
define noalias i8* @format_allele_index(i8 signext %0, i8 signext %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp slt i32 %4, 100
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call dereferenceable_or_null(5) i8* @calloc(i32 5, i32 1)
%9 = tail call i64 @is_unknown(i8 signext %0)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8 %0, i8 42
%12 = icmp eq i8 %11, %1
%13 = bitcast i8* %8 to i16*
br i1 %12, label %14, label %15
14: ; preds = %3
store i16 48, i16* %13
br label %32
15: ; preds = %3
store i16 46, i16* %13
%16 = icmp slt i32 %4, 1
br i1 %16, label %32, label %17
17: ; preds = %15
%18 = add nuw i32 %4, 1
%19 = zext i32 %18 to i64
br label %20
20: ; preds = %17, %29
%21 = phi i64 [ 1, %17 ], [ %30, %29 ]
%22 = add nsw i64 %21, -1
%23 = getelementptr inbounds i8, i8* %2, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, %11
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = trunc i64 %21 to i32
%28 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %32
29: ; preds = %20
%30 = add nuw nsw i64 %21, 1
%31 = icmp eq i64 %30, %19
br i1 %31, label %32, label %20
32: ; preds = %29, %15, %26, %14
ret i8* %8
}