#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 *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
int strlen(char const *);
char *MakeID(const char *name, int i) {
  int n;
  char *ID;
  int ndigits = 1;
  int remainder = i;
  while (remainder /= 10)
    ndigits++;
  n = strlen(name) + ndigits + 2;
  ID = malloc(n * sizeof(char));
  sprintf(ID, "%s%dX", name, i);
  return ID;
}


x86 assembly (clang, -O0):
<MakeID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1171 <MakeID+0x41>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114c <MakeID+0x1c>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe58(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeID>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x9(%rbx),%eax
mov    $0x3,%ebp
cmp    $0x13,%eax
jb     1174 <MakeID+0x44>
mov    $0x3,%ebp
mov    %ebx,%eax
nopl   (%rax)
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
lea    (%rcx,%rdx,1),%eax
add    %edx,%ecx
add    $0x9,%ecx
add    $0x1,%ebp
cmp    $0x12,%ecx
ja     1150 <MakeID+0x20>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
lea    0xe71(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1050 <sprintf@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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