#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 abs(double);
double fabs(double);
double fmod(double, double);
double modf(double, double *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int, double, int);
size_t strlen(char *);
size_t fmtdeg(char *strdeg, double d) {
  if (abs(d) > 360)
    d = fmod(d, 360.0);
  double fdegree, deg, m, s, tmp;
  fdegree = fabs(d);
  tmp = modf(fdegree, &deg);
  tmp = modf(tmp * 60.0, &m);
  s = tmp * 60;
  char *sign = "";
  if (d < 0)
    sign = "-";
  sprintf(strdeg, "%s%d°%d%c%.6f%c", sign, (int)(deg), (int)(m), 39, s, 34);
  return strlen(strdeg);
}


x86 assembly (clang, -O0):
<fmtdeg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <abs@plt>
cmp    $0x168,%eax
jle    118d <fmtdeg+0x3d>
movsd  -0x10(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
call   1050 <fmod@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xe77(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1060 <modf@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe4b(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
lea    -0x28(%rbp),%rdi
call   1060 <modf@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe30(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0xe38(%rip),%rax
mov    %rax,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1206 <fmtdeg+0xb6>
lea    0xe1e(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rdx
cvttsd2si -0x20(%rbp),%ecx
cvttsd2si -0x28(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xdfd(%rip),%rsi
mov    $0x27,%r9d
movl   $0x22,(%rsp)
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmtdeg>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movapd %xmm0,0x10(%rsp)
call   1030 <abs@plt>
cmp    $0x169,%eax
jl     1183 <fmtdeg+0x33>
movsd  0xe8e(%rip),%xmm1
movapd 0x10(%rsp),%xmm0
call   1050 <fmod@plt>
movapd %xmm0,%xmm1
jmp    1189 <fmtdeg+0x39>
movapd 0x10(%rsp),%xmm1
movapd %xmm1,0x10(%rsp)
movapd 0xe79(%rip),%xmm0
andpd  %xmm1,%xmm0
lea    0x28(%rsp),%rdi
call   1060 <modf@plt>
mulsd  0xe5b(%rip),%xmm0
lea    0x20(%rsp),%rdi
call   1060 <modf@plt>
xorpd  %xmm1,%xmm1
ucomisd 0x10(%rsp),%xmm1
lea    0xe58(%rip),%rax
lea    0xe52(%rip),%rdx
cmova  %rax,%rdx
cvttsd2si 0x28(%rsp),%ecx
mulsd  0xe27(%rip),%xmm0
cvttsd2si 0x20(%rsp),%r8d
movl   $0x22,(%rsp)
lea    0xe2c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x27,%r9d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
add    $0x30,%rsp
pop    %rbx
jmp    1040 <strlen@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [17 x i8] c"%s%d\C2\B0%d%c%.6f%c\00"
define i64 @fmtdeg(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i8*
store i8* %0, i8** %3
store double %1, double* %4
%11 = load double, double* %4
%12 = call i32 @abs(double %11)
%13 = icmp sgt i32 %12, 360
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load double, double* %4
%16 = call double @fmod(double %15, double 3.600000e+02)
store double %16, double* %4
br label %17
17: ; preds = %14, %2
%18 = load double, double* %4
%19 = call double @llvm.fabs.f64(double %18)
store double %19, double* %5
%20 = load double, double* %5
%21 = call double @modf(double %20, double* %6)
store double %21, double* %9
%22 = load double, double* %9
%23 = fmul double %22, 6.000000e+01
%24 = call double @modf(double %23, double* %7)
store double %24, double* %9
%25 = load double, double* %9
%26 = fmul double %25, 6.000000e+01
store double %26, double* %8
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %10
%27 = load double, double* %4
%28 = fcmp olt double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %17
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %30
30: ; preds = %29, %17
%31 = load i8*, i8** %3
%32 = load i8*, i8** %10
%33 = load double, double* %6
%34 = fptosi double %33 to i32
%35 = load double, double* %7
%36 = fptosi double %35 to i32
%37 = load double, double* %8
%38 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %34, i32 %36, i32 39, double %37, i32 34)
%39 = load i8*, i8** %3
%40 = call i64 @strlen(i8* %39)
ret i64 %40
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [17 x i8] c"%s%d\C2\B0%d%c%.6f%c\00"
define i64 @fmtdeg(i8* nocapture %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = tail call i32 @abs(double %1)
%6 = icmp sgt i32 %5, 360
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call double @fmod(double %1, double 3.600000e+02)
br label %9
9: ; preds = %7, %2
%10 = phi double [ %8, %7 ], [ %1, %2 ]
%11 = bitcast double* %3 to i8*
%12 = bitcast double* %4 to i8*
%13 = tail call double @llvm.fabs.f64(double %10)
%14 = call double @modf(double %13, double* %3)
%15 = fmul double %14, 6.000000e+01
%16 = call double @modf(double %15, double* %4)
%17 = fcmp olt double %10, 0.000000e+00
%18 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%19 = fmul double %16, 6.000000e+01
%20 = load double, double* %3
%21 = fptosi double %20 to i32
%22 = load double, double* %4
%23 = fptosi double %22 to i32
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %21, i32 %23, i32 39, double %19, i32 34)
%25 = tail call i64 @strlen(i8* dereferenceable(1) %0)
ret i64 %25
}