#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*/ sprintf(char *, char *, int, ...);
void three_digit(char *tx, int i) {
  if (i < 1000)
    sprintf(tx, "%d.%d", i / 10, i % 10);
  else
    sprintf(tx, "%d", i / 10);
}


x86 assembly (clang, -O0):
<three_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    1161 <three_digit+0x51>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x10(%rbp),%edx
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1180 <three_digit+0x70>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<three_digit>:
mov    %esi,%ecx
cmp    $0x3e7,%esi
jg     1147 <three_digit+0x37>
movslq %ecx,%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ecx
lea    0xec0(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
mov    %ecx,%eax
mov    $0xcccccccd,%edx
imul   %rax,%rdx
shr    $0x23,%rdx
lea    0xea6(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%d.%d\00"
@.str.1 = [3 x i8] c"%d\00"
define void @three_digit(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp slt i32 %5, 1000
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = load i32, i32* %4
%10 = sdiv i32 %9, 10
%11 = load i32, i32* %4
%12 = srem i32 %11, 10
%13 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %12)
br label %19
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%17 = sdiv i32 %16, 10
%18 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %14, %7
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d.%d\00"
@.str.1 = [3 x i8] c"%d\00"
define void @three_digit(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp slt i32 %1, 1000
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = sdiv i32 %1, 10
%6 = srem i32 %1, 10
%7 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
br label %11
8: ; preds = %2
%9 = udiv i32 %1, 10
%10 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %4
ret void
}