#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, int);
char *alt_ntoa(int32_t alt) {
  int32_t ref, m, frac, sign;
  static char buf[128];
  ref = 100000 * 100;
  sign = 1;
  if (alt < ref) {
    alt = ref - alt;
    sign = -1;
  } else {
    alt = alt - ref;
  }
  frac = alt % 100;
  m = (alt / 100) * sign;
  sprintf(buf, "%d.%.2d", m, frac);
  return buf;
}


x86 assembly (clang, -O0):
<alt_ntoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x989680,-0x8(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    114a <alt_ntoa+0x3a>
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0xffffffff,-0x14(%rbp)
jmp    1153 <alt_ntoa+0x43>
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
imul   -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0x2ec0(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1030 <sprintf@plt>
lea    0x2ead(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alt_ntoa>:
push   %rbx
lea    -0x989680(%rdi),%eax
neg    %eax
lea    -0x989680(%rdi),%ecx
cmp    $0x989680,%edi
cmovl  %eax,%ecx
movslq %ecx,%rcx
imul   $0x51eb851f,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rax
add    %edx,%eax
mov    %eax,%edx
neg    %edx
cmp    $0x989680,%edi
cmovge %eax,%edx
imul   $0x64,%eax,%eax
sub    %eax,%ecx
lea    0x2ee8(%rip),%rbx
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@alt_ntoa.buf = internal global [128 x i8] zeroinitializer
@.str = [8 x i8] c"%d.%.2d\00"
define i8* @alt_ntoa(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 10000000, i32* %3
store i32 1, i32* %6
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = sub nsw i32 %11, %12
store i32 %13, i32* %2
store i32 -1, i32* %6
br label %18
14: ; preds = %1
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = sub nsw i32 %15, %16
store i32 %17, i32* %2
br label %18
18: ; preds = %14, %10
%19 = load i32, i32* %2
%20 = srem i32 %19, 100
store i32 %20, i32* %5
%21 = load i32, i32* %2
%22 = sdiv i32 %21, 100
%23 = load i32, i32* %6
%24 = mul nsw i32 %22, %23
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @alt_ntoa.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @alt_ntoa.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@alt_ntoa.buf = internal global [128 x i8] zeroinitializer
@.str = [8 x i8] c"%d.%.2d\00"
define i8* @alt_ntoa(i32 %0) {
%2 = icmp slt i32 %0, 10000000
%3 = sub nsw i32 10000000, %0
%4 = add nsw i32 %0, -10000000
%5 = select i1 %2, i32 %3, i32 %4
%6 = srem i32 %5, 100
%7 = sdiv i32 %5, 100
%8 = sub nsw i32 0, %7
%9 = select i1 %2, i32 %8, i32 %7
%10 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([128 x i8], [128 x i8]* @alt_ntoa.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %6)
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @alt_ntoa.buf, i64 0, i64 0)
}