#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*/ snprintf(char *, int, char *, unsigned int, unsigned int);
const char *format_thousands(unsigned int value) {
  static char buf[4][15];
  static int i = 0;
  i = (i + 1) % 4;
  snprintf(buf[i], 15, "%d.%.3d", value / 1000, value % 1000);
  return buf[i];
}


x86 assembly (clang, -O0):
<format_thousands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2f5b(%rip),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,0x2f4a(%rip)
movslq 0x2f43(%rip),%rax
lea    0x2f00(%rip),%rdi
imul   $0xf,%rax,%rax
add    %rax,%rdi
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x4(%rbp),%eax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %esi
mov    %edx,%r8d
mov    $0xf,%esi
lea    0xe90(%rip),%rdx
call   1030 <snprintf@plt>
movslq 0x2f00(%rip),%rcx
lea    0x2ebd(%rip),%rax
imul   $0xf,%rcx,%rcx
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_thousands>:
push   %rbx
mov    %edi,%r8d
mov    0x2f62(%rip),%eax
lea    0x1(%rax),%ecx
lea    0x4(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xfffffffc,%edx
neg    %edx
add    %edx,%eax
add    $0x1,%eax
mov    %eax,0x2f47(%rip)
lea    (%rax,%rax,4),%rax
lea    (%rax,%rax,2),%rdi
lea    0x2efc(%rip),%rbx
add    %rbx,%rdi
mov    %r8d,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
imul   $0x3e8,%ecx,%eax
sub    %eax,%r8d
lea    0xe9b(%rip),%rdx
mov    $0xf,%esi
call   1030 <snprintf@plt>
mov    0x2f07(%rip),%eax
lea    (%rax,%rax,4),%rax
lea    (%rax,%rax,2),%rax
add    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@format_thousands.buf = internal global [4 x [15 x i8]] zeroinitializer
@format_thousands.i = internal global i32 0
@.str = [8 x i8] c"%d.%.3d\00"
define i8* @format_thousands(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @format_thousands.i
%4 = add nsw i32 %3, 1
%5 = srem i32 %4, 4
store i32 %5, i32* @format_thousands.i
%6 = load i32, i32* @format_thousands.i
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [4 x [15 x i8]], [4 x [15 x i8]]* @format_thousands.buf, i64 0, i64 %7
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%10 = load i32, i32* %2
%11 = udiv i32 %10, 1000
%12 = load i32, i32* %2
%13 = urem i32 %12, 1000
%14 = call i32 @snprintf(i8* %9, i32 15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13)
%15 = load i32, i32* @format_thousands.i
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x [15 x i8]], [4 x [15 x i8]]* @format_thousands.buf, i64 0, i64 %16
%18 = getelementptr inbounds [15 x i8], [15 x i8]* %17, i64 0, i64 0
ret i8* %18
}

LLVM IR (-O2):
@format_thousands.buf = internal global [4 x [15 x i8]] zeroinitializer
@format_thousands.i = internal unnamed_addr global i32 0
@.str = [8 x i8] c"%d.%.3d\00"
define i8* @format_thousands(i32 %0) {
%2 = load i32, i32* @format_thousands.i
%3 = add nsw i32 %2, 1
%4 = srem i32 %3, 4
store i32 %4, i32* @format_thousands.i
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [4 x [15 x i8]], [4 x [15 x i8]]* @format_thousands.buf, i64 0, i64 %5, i64 0
%7 = udiv i32 %0, 1000
%8 = urem i32 %0, 1000
%9 = tail call i32 @snprintf(i8* %6, i32 15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = load i32, i32* @format_thousands.i
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [4 x [15 x i8]], [4 x [15 x i8]]* @format_thousands.buf, i64 0, i64 %11, i64 0
ret i8* %12
}