#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*/ memmove(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int);
int strlen(char *);
char *gcspy_formatLargeNumber(unsigned int num) {
  static char buffer[128];
  int curr;
  sprintf(buffer, "%u", num);
  curr = strlen(buffer) - 3;
  while (curr > 0) {
    memmove(&buffer[curr + 1], &buffer[curr], strlen(buffer) - curr + 1);
    buffer[curr] = ',';
    curr -= 3;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<gcspy_formatLargeNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
lea    0x2f0b(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2ef8(%rip),%rdi
call   1030 <strlen@plt>
sub    $0x3,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11d4 <gcspy_formatLargeNumber+0xa4>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2ed3(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movslq -0x8(%rbp),%rcx
lea    0x2ec1(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
lea    0x2eb3(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
sub    -0x8(%rbp),%edx
add    $0x1,%edx
call   1040 <memmove@plt>
movslq -0x8(%rbp),%rcx
lea    0x2e8e(%rip),%rax
movb   $0x2c,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x8(%rbp)
jmp    1163 <gcspy_formatLargeNumber+0x33>
lea    0x2e75(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcspy_formatLargeNumber>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%edx
lea    0x2f0f(%rip),%r14
lea    0xeb8(%rip),%rsi
mov    %r14,%rdi
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
jl     11ae <gcspy_formatLargeNumber+0x7e>
mov    %eax,%r15d
lea    0x3(%r15),%r12d
mov    $0x4,%ebp
sub    %eax,%ebp
lea    -0x3(%r15),%ebx
add    %r14,%rbx
add    $0xfffffffe,%r15d
add    %r14,%r15
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbp,1),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <memmove@plt>
movb   $0x2c,(%rbx)
add    $0xfffffffd,%r12d
add    $0x3,%ebp
add    $0xfffffffffffffffd,%rbx
add    $0xfffffffffffffffd,%r15
cmp    $0x6,%r12d
ja     1180 <gcspy_formatLargeNumber+0x50>
lea    0x2e9b(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@gcspy_formatLargeNumber.buffer = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
define i8* @gcspy_formatLargeNumber(i32 %0) {
%2 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @gcspy_formatLargeNumber.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @gcspy_formatLargeNumber.buffer, i64 0, i64 0))
%4 = icmp sgt i32 %3, 3
br i1 %4, label %5, label %18
5: ; preds = %1, %5
%6 = phi i32 [ %7, %5 ], [ %3, %1 ]
%7 = add nsw i32 %6, -3
%8 = add nsw i32 %6, -2
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [128 x i8], [128 x i8]* @gcspy_formatLargeNumber.buffer, i64 0, i64 %9
%11 = zext i32 %7 to i64
%12 = getelementptr inbounds [128 x i8], [128 x i8]* @gcspy_formatLargeNumber.buffer, i64 0, i64 %11
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @gcspy_formatLargeNumber.buffer, i64 0, i64 0))
%14 = sub nsw i32 4, %6
%15 = add i32 %14, %13
%16 = tail call i32 @memmove(i8* %10, i8* %12, i32 %15)
store i8 44, i8* %12
%17 = icmp ugt i32 %6, 6
br i1 %17, label %5, label %18
18: ; preds = %5, %1
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @gcspy_formatLargeNumber.buffer, i64 0, i64 0)
}