#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 */
double modf(double, double *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int);
int deg_to_str(double f, char *buf, int buf_size) {
  double fsec, fdeg, fmin;
  if (buf_size <= 0)
    return -1;
  *buf = 0;
  if (f < 0 || f > 360)
    return -1;
  fmin = modf(f, &fdeg);
  fsec = modf(fmin * 60, &fmin);
  fsec *= 60;
  snprintf(buf, buf_size, "%03d/1,%02d/1,%05d/1000", (int)fdeg, (int)fmin,
           (int)(fsec * 1000));
  return 0;
}


x86 assembly (clang, -O0):
<deg_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     114a <deg_to_str+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <deg_to_str+0xd9>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     1176 <deg_to_str+0x56>
movsd  -0x10(%rbp),%xmm0
movsd  0xe94(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1182 <deg_to_str+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <deg_to_str+0xd9>
movsd  -0x10(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe73(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
lea    -0x38(%rbp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  0xe58(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
cvttsd2si -0x30(%rbp),%ecx
cvttsd2si -0x38(%rbp),%r8d
movsd  0xe2c(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%r9d
lea    0xe2b(%rip),%rdx
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deg_to_str>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
test   %esi,%esi
jle    11a3 <deg_to_str+0x83>
mov    %rdi,%r14
movb   $0x0,(%rdi)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11a3 <deg_to_str+0x83>
ucomisd 0xeb8(%rip),%xmm0
ja     11a3 <deg_to_str+0x83>
mov    %esi,%ebx
lea    0x10(%rsp),%rdi
call   1040 <modf@plt>
movsd  %xmm0,0x8(%rsp)
mulsd  0xea4(%rip),%xmm0
lea    0x8(%rsp),%rdi
call   1040 <modf@plt>
cvttsd2si 0x10(%rsp),%ecx
mulsd  0xe8c(%rip),%xmm0
cvttsd2si 0x8(%rsp),%r8d
mulsd  0xe85(%rip),%xmm0
cvttsd2si %xmm0,%r9d
lea    0xe81(%rip),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <snprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%03d/1,%02d/1,%05d/1000\00"
define i32 @deg_to_str(double %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %40
14: ; preds = %3
%15 = load i8*, i8** %6
store i8 0, i8* %15
%16 = load double, double* %5
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load double, double* %5
%20 = fcmp ogt double %19, 3.600000e+02
br i1 %20, label %21, label %22
21: ; preds = %18, %14
store i32 -1, i32* %4
br label %40
22: ; preds = %18
%23 = load double, double* %5
%24 = call double @modf(double %23, double* %9)
store double %24, double* %10
%25 = load double, double* %10
%26 = fmul double %25, 6.000000e+01
%27 = call double @modf(double %26, double* %10)
store double %27, double* %8
%28 = load double, double* %8
%29 = fmul double %28, 6.000000e+01
store double %29, double* %8
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = load double, double* %9
%33 = fptosi double %32 to i32
%34 = load double, double* %10
%35 = fptosi double %34 to i32
%36 = load double, double* %8
%37 = fmul double %36, 1.000000e+03
%38 = fptosi double %37 to i32
%39 = call i32 @snprintf(i8* %30, i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %35, i32 %38)
store i32 0, i32* %4
br label %40
40: ; preds = %22, %21, %13
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [24 x i8] c"%03d/1,%02d/1,%05d/1000\00"
define i32 @deg_to_str(double %0, i8* %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = bitcast double* %4 to i8*
%7 = bitcast double* %5 to i8*
%8 = icmp slt i32 %2, 1
br i1 %8, label %25, label %9
9: ; preds = %3
store i8 0, i8* %1
%10 = fcmp olt double %0, 0.000000e+00
%11 = fcmp ogt double %0, 3.600000e+02
%12 = or i1 %10, %11
br i1 %12, label %25, label %13
13: ; preds = %9
%14 = call double @modf(double %0, double* %4)
store double %14, double* %5
%15 = fmul double %14, 6.000000e+01
%16 = call double @modf(double %15, double* %5)
%17 = fmul double %16, 6.000000e+01
%18 = load double, double* %4
%19 = fptosi double %18 to i32
%20 = load double, double* %5
%21 = fptosi double %20 to i32
%22 = fmul double %17, 1.000000e+03
%23 = fptosi double %22 to i32
%24 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %21, i32 %23)
br label %25
25: ; preds = %9, %3, %13
%26 = phi i32 [ 0, %13 ], [ -1, %3 ], [ -1, %9 ]
ret i32 %26
}