#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 /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
char *convpari(int num) {
  int mask = 1;
  int esp = 0;
  char *res = (char *)malloc(15 * sizeof(char));
  while ((mask & num) == 0) {
    num = num >> 1;
    esp++;
  }
  sprintf(res, "%d", num);
  strcat(res, "b");
  sprintf(res, "%s%d", res, esp);
  return res;
}


x86 assembly (clang, -O0):
<convpari>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0xf,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    -0x4(%rbp),%eax
cmp    $0x0,%eax
jne    117d <convpari+0x4d>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1157 <convpari+0x27>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convpari>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    $0xf,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
xor    %ebp,%ebp
test   $0x1,%bl
jne    115e <convpari+0x2e>
xor    %ebp,%ebp
mov    %ebx,%edx
xchg   %ax,%ax
sar    %edx
add    $0x1,%ebp
test   $0x2,%bl
mov    %edx,%ebx
je     1150 <convpari+0x20>
jmp    1160 <convpari+0x30>
mov    %ebx,%edx
lea    0xe9d(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe88(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
lea    0xe7b(%rip),%rsi
mov    %r14,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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