#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 nearbyint(double);
int /*<<< orphan*/ sprintf(char *, char *, ...);
size_t strlen(char *);
char *sprint_fractional_12(char *string, double v) {
  int d, p1, p2, neg = 0, n;
  if (v < 0.) {
    neg = 1;
    v = -v;
  }
  d = nearbyint(v * 144.);
  if (d == 0)
    neg = 0;
  p2 = d % 12;
  d /= 12;
  p1 = d % 12;
  d /= 12;
  string[0] = 0;
  if (neg)
    sprintf(string, "-");
  if (p2)
    sprintf(&string[strlen(string)], "%d;%d;%d", d, p1, p2);
  else if (p1)
    sprintf(&string[strlen(string)], "%d;%d", d, p1);
  else
    sprintf(&string[strlen(string)], "%d", d);
  return string;
}


x86 assembly (clang, -O0):
<sprint_fractional_12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    117e <sprint_fractional_12+0x4e>
movl   $0x1,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe7a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <nearbyint@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a4 <sprint_fractional_12+0x74>
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x20(%rbp)
je     11ff <sprint_fractional_12+0xcf>
mov    -0x8(%rbp),%rdi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     123e <sprint_fractional_12+0x10e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12a7 <sprint_fractional_12+0x177>
cmpl   $0x0,-0x18(%rbp)
je     1279 <sprint_fractional_12+0x149>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12a2 <sprint_fractional_12+0x172>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
mov    -0x14(%rbp),%edx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    12a7 <sprint_fractional_12+0x177>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_fractional_12>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movapd %xmm0,%xmm2
movapd %xmm0,(%rsp)
mov    %rdi,%r14
movapd 0xeb2(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
mulsd  0xea1(%rip),%xmm0
call   1040 <nearbyint@plt>
movslq %eax,%rcx
imul   $0x2aaaaaab,%rcx,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rbx
add    %edx,%ebx
lea    0x0(,%rbx,4),%edx
lea    (%rdx,%rdx,2),%edx
imul   $0x38e38e39,%rcx,%r15
mov    %ecx,%ebp
sub    %edx,%ebp
movslq %ebx,%rcx
imul   $0x2aaaaaab,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x21,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,2),%edx
mov    %r15,%rcx
shr    $0x3f,%rcx
sar    $0x25,%r15
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
movb   $0x0,(%r14)
jbe    11e1 <sprint_fractional_12+0xb1>
test   %eax,%eax
je     11e1 <sprint_fractional_12+0xb1>
movw   $0x2d,(%r14)
sub    %edx,%ebx
add    %ecx,%r15d
mov    %r14,%rdi
test   %ebp,%ebp
je     120e <sprint_fractional_12+0xde>
call   1030 <strlen@plt>
lea    (%rax,%r14,1),%rdi
lea    0xe23(%rip),%rsi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1246 <sprint_fractional_12+0x116>
call   1030 <strlen@plt>
add    %r14,%rax
test   %ebx,%ebx
je     1232 <sprint_fractional_12+0x102>
lea    0xe02(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1246 <sprint_fractional_12+0x116>
lea    0xded(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [9 x i8] c"%d;%d;%d\00"
@.str.2 = [6 x i8] c"%d;%d\00"
@.str.3 = [3 x i8] c"%d\00"
define i8* @sprint_fractional_12(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store double %1, double* %4
store i32 0, i32* %8
%10 = load double, double* %4
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %2
store i32 1, i32* %8
%13 = load double, double* %4
%14 = fneg double %13
store double %14, double* %4
br label %15
15: ; preds = %12, %2
%16 = load double, double* %4
%17 = fmul double %16, 1.440000e+02
%18 = call i32 @nearbyint(double %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %8
br label %22
22: ; preds = %21, %15
%23 = load i32, i32* %5
%24 = srem i32 %23, 12
store i32 %24, i32* %7
%25 = load i32, i32* %5
%26 = sdiv i32 %25, 12
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = srem i32 %27, 12
store i32 %28, i32* %6
%29 = load i32, i32* %5
%30 = sdiv i32 %29, 12
store i32 %30, i32* %5
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 0, i8* %32
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %22
%36 = load i8*, i8** %3
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %38
38: ; preds = %35, %22
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i8*, i8** %3
%43 = load i8*, i8** %3
%44 = call i64 @strlen(i8* %43)
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %47, i32 %48)
br label %69
50: ; preds = %38
%51 = load i32, i32* %6
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i8*, i8** %3
%55 = load i8*, i8** %3
%56 = call i64 @strlen(i8* %55)
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i32, i32* %5
%59 = load i32, i32* %6
%60 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %58, i32 %59)
br label %68
61: ; preds = %50
%62 = load i8*, i8** %3
%63 = load i8*, i8** %3
%64 = call i64 @strlen(i8* %63)
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i32, i32* %5
%67 = call i32 (i8*, i8*, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %61, %53
br label %69
69: ; preds = %68, %41
%70 = load i8*, i8** %3
ret i8* %70
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"%d;%d;%d\00"
@.str.2 = [6 x i8] c"%d;%d\00"
@.str.3 = [3 x i8] c"%d\00"
define i8* @sprint_fractional_12(i8* returned %0, double %1) {
%3 = fcmp olt double %1, 0.000000e+00
%4 = fneg double %1
%5 = select i1 %3, double %4, double %1
%6 = fmul double %5, 1.440000e+02
%7 = tail call i32 @nearbyint(double %6)
%8 = icmp ne i32 %7, 0
%9 = and i1 %3, %8
%10 = srem i32 %7, 12
%11 = sdiv i32 %7, 12
%12 = srem i32 %11, 12
%13 = sdiv i32 %7, 144
store i8 0, i8* %0
br i1 %9, label %14, label %16
14: ; preds = %2
%15 = bitcast i8* %0 to i16*
store i16 45, i16* %15
br label %16
16: ; preds = %14, %2
%17 = icmp eq i32 %10, 0
br i1 %17, label %22, label %18
18: ; preds = %16
%19 = tail call i64 @strlen(i8* %0)
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %12, i32 %10)
br label %30
22: ; preds = %16
%23 = icmp eq i32 %12, 0
%24 = tail call i64 @strlen(i8* %0)
%25 = getelementptr inbounds i8, i8* %0, i64 %24
br i1 %23, label %28, label %26
26: ; preds = %22
%27 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %12)
br label %30
28: ; preds = %22
%29 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %30
30: ; preds = %26, %28, %18
ret i8* %0
}