#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*/ regPrintVal(double, char *);
int /*<<< orphan*/ sprintf(char *, char *, long, long, long, char *);
void regPrintPos(double x, int world, char *buf) {
  char tmp[80];
  char *ptr;
  long h, m;
  double s;
  double fs;
  long is;
  int south;
  if (world) {
    south = x < 0;
    s = x * 3600.0;
    if (south)
      s = -s;
    is = (long)s;
    if (s - is > 0.9999) {
      is++;
      fs = 0;
    } else {
      fs = s - is;
    }
    m = is / 60;
    is = is % 60;
    h = m / 60;
    m = m % 60;
    regPrintVal(fs, tmp);
    ptr = tmp;
    if (*ptr == '0')
      ptr++;
    if (south)
      sprintf(buf, "-%02ld:%02ld:%02ld%s", h, m, is, ptr);
    else
      sprintf(buf, "%02ld:%02ld:%02ld%s", h, m, is, ptr);
  } else {
    regPrintVal(x, buf);
  }
}


x86 assembly (clang, -O0):
<regPrintPos>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     130b <regPrintPos+0x1eb>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xa4(%rbp)
movsd  0xea1(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
cmpl   $0x0,-0xa4(%rbp)
je     11a0 <regPrintPos+0x80>
movsd  -0x90(%rbp),%xmm0
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
cvttsd2si -0x90(%rbp),%rax
ff ff
mov    %rax,-0xa0(%rbp)
movsd  -0x90(%rbp),%xmm0
ff
cvtsi2sdq -0xa0(%rbp),%xmm1
ff ff
subsd  %xmm1,%xmm0
movsd  0xe3b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f9 <regPrintPos+0xd9>
mov    -0xa0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
jmp    1216 <regPrintPos+0xf6>
movsd  -0x90(%rbp),%xmm0
cvtsi2sdq -0xa0(%rbp),%xmm1
ff ff
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
mov    -0xa0(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x88(%rbp)
mov    -0xa0(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0xa0(%rbp)
mov    -0x88(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x80(%rbp)
mov    -0x88(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x88(%rbp)
movsd  -0x98(%rbp),%xmm0
ff
lea    -0x70(%rbp),%rdi
call   1030 <regPrintVal@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    12a8 <regPrintPos+0x188>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0xa4(%rbp)
je     12e0 <regPrintPos+0x1c0>
mov    -0x18(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    -0x88(%rbp),%rcx
mov    -0xa0(%rbp),%r8
mov    -0x78(%rbp),%r9
lea    0xd3a(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1306 <regPrintPos+0x1e6>
mov    -0x18(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    -0x88(%rbp),%rcx
mov    -0xa0(%rbp),%r8
mov    -0x78(%rbp),%r9
lea    0xd10(%rip),%rsi
call   1040 <sprintf@plt>
jmp    1319 <regPrintPos+0x1f9>
movsd  -0x8(%rbp),%xmm0
mov    -0x18(%rbp),%rdi
call   1030 <regPrintVal@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regPrintPos>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%r14
test   %edi,%edi
je     123c <regPrintPos+0x11c>
movsd  0xec0(%rip),%xmm4
mulsd  %xmm0,%xmm4
movapd 0xed4(%rip),%xmm2
xorpd  %xmm4,%xmm2
xorpd  %xmm3,%xmm3
movsd  %xmm0,0x8(%rsp)
movapd %xmm0,%xmm1
cmpltsd %xmm3,%xmm1
movapd %xmm1,%xmm3
andnpd %xmm4,%xmm3
andpd  %xmm2,%xmm1
orpd   %xmm3,%xmm1
cvttsd2si %xmm1,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  %xmm0,%xmm1
xor    %r15d,%r15d
ucomisd 0xe79(%rip),%xmm1
seta   %cl
xorpd  %xmm0,%xmm0
ja     119c <regPrintPos+0x7c>
movapd %xmm1,%xmm0
mov    %cl,%r15b
add    %rax,%r15
movabs $0x8888888888888889,%rcx
88 88 88
mov    %r15,%rax
imul   %rcx
mov    %rdx,%rbx
add    %r15,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x5,%rbx
add    %rax,%rbx
movabs $0x48d159e26af37c05,%rdx
59 d1 48
mov    %r15,%rax
imul   %rdx
mov    %rdx,%r12
imul   $0x3c,%rbx,%rax
sub    %rax,%r15
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xa,%r12
add    %rax,%r12
mov    %rbx,%rax
imul   %rcx
add    %rbx,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x5,%rdx
add    %rax,%rdx
imul   $0x3c,%rdx,%rax
sub    %rax,%rbx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
call   1030 <regPrintVal@plt>
cmpb   $0x30,0x10(%rsp)
lea    0x11(%rsp),%r9
cmovne %r13,%r9
xorpd  %xmm0,%xmm0
ucomisd 0x8(%rsp),%xmm0
jbe    1251 <regPrintPos+0x131>
lea    0xdf6(%rip),%rsi
jmp    1258 <regPrintPos+0x138>
mov    %r14,%rdi
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <regPrintVal@plt>
lea    0xdd9(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
call   1040 <sprintf@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"-%02ld:%02ld:%02ld%s\00"
@.str.1 = [20 x i8] c"%02ld:%02ld:%02ld%s\00"
define void @regPrintPos(double %0, i32 %1, i8* %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [80 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca double
%12 = alloca double
%13 = alloca i64
%14 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %82
17: ; preds = %3
%18 = load double, double* %4
%19 = fcmp olt double %18, 0.000000e+00
%20 = zext i1 %19 to i32
store i32 %20, i32* %14
%21 = load double, double* %4
%22 = fmul double %21, 3.600000e+03
store double %22, double* %11
%23 = load i32, i32* %14
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load double, double* %11
%27 = fneg double %26
store double %27, double* %11
br label %28
28: ; preds = %25, %17
%29 = load double, double* %11
%30 = fptosi double %29 to i64
store i64 %30, i64* %13
%31 = load double, double* %11
%32 = load i64, i64* %13
%33 = sitofp i64 %32 to double
%34 = fsub double %31, %33
%35 = fcmp ogt double %34, 9.999000e-01
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i64, i64* %13
%38 = add nsw i64 %37, 1
store i64 %38, i64* %13
store double 0.000000e+00, double* %12
br label %44
39: ; preds = %28
%40 = load double, double* %11
%41 = load i64, i64* %13
%42 = sitofp i64 %41 to double
%43 = fsub double %40, %42
store double %43, double* %12
br label %44
44: ; preds = %39, %36
%45 = load i64, i64* %13
%46 = sdiv i64 %45, 60
store i64 %46, i64* %10
%47 = load i64, i64* %13
%48 = srem i64 %47, 60
store i64 %48, i64* %13
%49 = load i64, i64* %10
%50 = sdiv i64 %49, 60
store i64 %50, i64* %9
%51 = load i64, i64* %10
%52 = srem i64 %51, 60
store i64 %52, i64* %10
%53 = load double, double* %12
%54 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%55 = call i32 @regPrintVal(double %53, i8* %54)
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
store i8* %56, i8** %8
%57 = load i8*, i8** %8
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 48
br i1 %60, label %61, label %64
61: ; preds = %44
%62 = load i8*, i8** %8
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %8
br label %64
64: ; preds = %61, %44
%65 = load i32, i32* %14
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %74
67: ; preds = %64
%68 = load i8*, i8** %6
%69 = load i64, i64* %9
%70 = load i64, i64* %10
%71 = load i64, i64* %13
%72 = load i8*, i8** %8
%73 = call i32 @sprintf(i8* %68, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %69, i64 %70, i64 %71, i8* %72)
br label %81
74: ; preds = %64
%75 = load i8*, i8** %6
%76 = load i64, i64* %9
%77 = load i64, i64* %10
%78 = load i64, i64* %13
%79 = load i8*, i8** %8
%80 = call i32 @sprintf(i8* %75, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 %76, i64 %77, i64 %78, i8* %79)
br label %81
81: ; preds = %74, %67
br label %86
82: ; preds = %3
%83 = load double, double* %4
%84 = load i8*, i8** %6
%85 = call i32 @regPrintVal(double %83, i8* %84)
br label %86
86: ; preds = %82, %81
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"-%02ld:%02ld:%02ld%s\00"
@.str.1 = [20 x i8] c"%02ld:%02ld:%02ld%s\00"
define void @regPrintPos(double %0, i32 %1, i8* %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %1, 0
br i1 %6, label %32, label %7
7: ; preds = %3
%8 = fcmp olt double %0, 0.000000e+00
%9 = fmul double %0, 3.600000e+03
%10 = fneg double %9
%11 = select i1 %8, double %10, double %9
%12 = fptosi double %11 to i64
%13 = sitofp i64 %12 to double
%14 = fsub double %11, %13
%15 = fcmp ogt double %14, 9.999000e-01
%16 = select i1 %15, double 0.000000e+00, double %14
%17 = zext i1 %15 to i64
%18 = add nsw i64 %17, %12
%19 = sdiv i64 %18, 60
%20 = srem i64 %18, 60
%21 = sdiv i64 %18, 3600
%22 = srem i64 %19, 60
%23 = call i32 @regPrintVal(double %16, i8* %5)
%24 = load i8, i8* %5
%25 = icmp eq i8 %24, 48
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 1
%27 = select i1 %25, i8* %26, i8* %5
br i1 %8, label %28, label %30
28: ; preds = %7
%29 = call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %21, i64 %22, i64 %20, i8* %27)
br label %34
30: ; preds = %7
%31 = call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 %21, i64 %22, i64 %20, i8* %27)
br label %34
32: ; preds = %3
%33 = tail call i32 @regPrintVal(double %0, i8* %2)
br label %34
34: ; preds = %28, %30, %32
ret void
}