#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__ malloc(int);
int qualifier_index(char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
int strlen(char const *);
char *mk_comparable_qualifier(const char *str) {
  int idx = qualifier_index(str);
  if (idx == -1) {
    size_t size = strlen(str) + 3;
    char *ret = (char *)malloc(size);
    snprintf(ret, size, "%d-%s", 7, str);
    return ret;
  }
  char *ret = (char *)malloc(2);
  snprintf(ret, 2, "%d", idx);
  return ret;
}


x86 assembly (clang, -O0):
<mk_comparable_qualifier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <qualifier_index@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11b1 <mk_comparable_qualifier+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x3,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%r8
lea    0xe68(%rip),%rdx
mov    $0x7,%ecx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e1 <mk_comparable_qualifier+0xa1>
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x2,%esi
lea    0xe34(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_comparable_qualifier>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1060 <qualifier_index@plt>
cmp    $0xffffffff,%eax
je     117a <mk_comparable_qualifier+0x3a>
mov    %eax,%ebp
mov    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe9f(%rip),%rdx
mov    %rax,%rdi
mov    $0x2,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    11aa <mk_comparable_qualifier+0x6a>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x3(%rax),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe6a(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x7,%ecx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d-%s\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @mk_comparable_qualifier(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @qualifier_index(i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %27
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 3
%16 = sext i32 %15 to i64
store i64 %16, i64* %5
%17 = load i64, i64* %5
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i64, i64* %5
%23 = trunc i64 %22 to i32
%24 = load i8*, i8** %3
%25 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %21, i32 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 7, i8* %24)
%26 = load i8*, i8** %6
store i8* %26, i8** %2
br label %34
27: ; preds = %1
%28 = call i64 @malloc(i32 2)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = load i32, i32* %4
%32 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %30, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i8*, i8** %7
store i8* %33, i8** %2
br label %34
34: ; preds = %27, %12
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d-%s\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @mk_comparable_qualifier(i8* %0) {
%2 = tail call i32 @qualifier_index(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, 3
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %8, i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 7, i8* %0)
br label %14
10: ; preds = %1
%11 = tail call i64 @malloc(i32 2)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* %12, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %14
14: ; preds = %10, %4
%15 = phi i8* [ %8, %4 ], [ %12, %10 ]
ret i8* %15
}