#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 */
typedef int /*<<< orphan*/ name;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
char *addLineCountToVariable(char *name, int linecount) {
  int stellenDerZahl = 1;
  int zehnerpotenz = 10;
  while ((linecount - zehnerpotenz) > 0) {
    stellenDerZahl++;
    zehnerpotenz *= 10;
  }
  char *text =
      malloc((sizeof(name) / sizeof(name[0])) + 1 + stellenDerZahl + 1);
  sprintf(text, "%s_%d", name, linecount);
  return text;
}


x86 assembly (clang, -O0):
<addLineCountToVariable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x0,%eax
jle    1161 <addLineCountToVariable+0x41>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113d <addLineCountToVariable+0x1d>
movslq -0x10(%rbp),%rax
add    $0x9,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe76(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addLineCountToVariable>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    $0xb,%edi
cmp    $0xb,%esi
jl     114c <addLineCountToVariable+0x2c>
mov    $0xa,%eax
mov    $0xb,%edi
xchg   %ax,%ax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
add    $0x1,%edi
cmp    %ebx,%eax
jl     1140 <addLineCountToVariable+0x20>
call   1030 <malloc@plt>
mov    %rax,%r15
lea    0xea5(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1040 <sprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s_%d\00"
define noalias i8* @addLineCountToVariable(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 10
br i1 %3, label %4, label %12
4: ; preds = %2, %4
%5 = phi i32 [ %7, %4 ], [ 1, %2 ]
%6 = phi i32 [ %8, %4 ], [ 10, %2 ]
%7 = add nuw nsw i32 %5, 1
%8 = mul nsw i32 %6, 10
%9 = icmp slt i32 %8, %1
br i1 %9, label %4, label %10
10: ; preds = %4
%11 = add nuw i32 %5, 11
br label %12
12: ; preds = %10, %2
%13 = phi i32 [ 11, %2 ], [ %11, %10 ]
%14 = tail call i8* @malloc(i32 %13)
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
ret i8* %14
}