#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 pow(int, double);
int /*<<< orphan*/ sprintf(char *, char *, int, int, double, ...);
char *strchr(char *, char);
scalar_t__ strstr(char *, char *);
char *angle_fmt(double a, char *format, char *lin) {
  char s, *p;
  int d, min, n;
  double sec, msec;
  if (a >= 0.)
    s = '+';
  else {
    s = '-';
    a = -a;
  }
  d = (int)(a / 3600.);
  min = (int)((a - (double)d * 3600.) / 60.);
  sec = a - (double)d * 3600. - (double)min * 60.;
  d %= 360;
  if ((p = strchr(format, '.')) == NULL)
    msec = 59.;
  else if (*(p + 2) == 'f') {
    n = *(p + 1) - '0';
    msec = 60. - pow(10., (double)(-n));
  } else
    msec = 60.;
  if (sec > msec)
    sec = msec;
  if (strstr(format, "%c"))
    sprintf(lin, format, s, d, min, sec);
  else
    sprintf(lin, format, d, min, sec);
  return lin;
}


x86 assembly (clang, -O0):
<angle_fmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1170 <angle_fmt+0x30>
movb   $0x2b,-0x19(%rbp)
jmp    1195 <angle_fmt+0x55>
movb   $0x2d,-0x19(%rbp)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe32(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe1a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdee(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdba(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x168,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    128f <angle_fmt+0x14f>
movsd  0xd8b(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12ed <angle_fmt+0x1ad>
mov    -0x28(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x66,%eax
jne    12db <angle_fmt+0x19b>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
sub    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd33(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12e8 <angle_fmt+0x1a8>
movsd  0xd1d(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    12ed <angle_fmt+0x1ad>
movsd  -0x40(%rbp),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1307 <angle_fmt+0x1c7>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xd06(%rip),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     1346 <angle_fmt+0x206>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsbl -0x19(%rbp),%edx
mov    -0x2c(%rbp),%ecx
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    $0x2,%al
call   1050 <sprintf@plt>
jmp    1360 <angle_fmt+0x220>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
movsd  -0x40(%rbp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<angle_fmt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
xorpd  %xmm1,%xmm1
xor    %r15d,%r15d
ucomisd %xmm1,%xmm0
setb   %r12b
jae    116d <angle_fmt+0x2d>
xorpd  0xe93(%rip),%xmm0
movsd  0xe9b(%rip),%xmm2
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%ebp
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe7f(%rip),%xmm2
movapd %xmm0,%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,0x10(%rsp)
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
movapd %xmm1,0x20(%rsp)
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movapd %xmm0,(%rsp)
movslq %ebp,%rax
imul   $0xffffffffb60b60b7,%rax,%rax
shr    $0x20,%rax
add    %ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x8,%eax
add    %ecx,%eax
imul   $0x168,%eax,%ebx
mov    %r13,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1233 <angle_fmt+0xf3>
cmpb   $0x66,0x2(%rax)
movsd  0xe18(%rip),%xmm1
jne    123b <angle_fmt+0xfb>
movsbl 0x1(%rax),%eax
mov    $0x30,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mov    $0xa,%edi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xdeb(%rip),%xmm1
subsd  %xmm0,%xmm1
jmp    123b <angle_fmt+0xfb>
movsd  0xde5(%rip),%xmm1
minsd  (%rsp),%xmm1
movsd  %xmm1,(%rsp)
sub    %ebx,%ebp
lea    0xdda(%rip),%rsi
mov    %r13,%rdi
call   1060 <strstr@plt>
test   %rax,%rax
je     1280 <angle_fmt+0x140>
mov    %r12b,%r15b
lea    (%r15,%r15,1),%edx
add    $0x2b,%edx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%ecx
movaps 0x20(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    $0x2,%al
call   1050 <sprintf@plt>
jmp    129a <angle_fmt+0x15a>
cvttsd2si 0x10(%rsp),%ecx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define i8* @angle_fmt(double %0, i8* %1, i8* returned writeonly %2) {
%4 = fcmp ult double %0, 0.000000e+00
%5 = fneg double %0
%6 = select i1 %4, i32 45, i32 43
%7 = select i1 %4, double %5, double %0
%8 = fdiv double %7, 3.600000e+03
%9 = fptosi double %8 to i32
%10 = sitofp i32 %9 to double
%11 = fneg double %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double 3.600000e+03, double %7)
%13 = fdiv double %12, 6.000000e+01
%14 = fptosi double %13 to i32
%15 = sitofp i32 %14 to double
%16 = fneg double %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double 6.000000e+01, double %12)
%18 = srem i32 %9, 360
%19 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 46)
%20 = icmp eq i8* %19, null
br i1 %20, label %34, label %21
21: ; preds = %3
%22 = getelementptr inbounds i8, i8* %19, i64 2
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 102
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = getelementptr inbounds i8, i8* %19, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = sub nsw i32 48, %28
%30 = sitofp i32 %29 to double
%31 = tail call i32 @pow(i32 10, double %30)
%32 = sitofp i32 %31 to double
%33 = fsub double 6.000000e+01, %32
br label %34
34: ; preds = %21, %3, %25
%35 = phi double [ %33, %25 ], [ 5.900000e+01, %3 ], [ 6.000000e+01, %21 ]
%36 = fcmp ogt double %17, %35
%37 = select i1 %36, double %35, double %17
%38 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %34
%41 = tail call i32 (i8*, i8*, i32, i32, double, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) %1, i32 %6, i32 %18, double %15, double %37)
br label %44
42: ; preds = %34
%43 = tail call i32 (i8*, i8*, i32, i32, double, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) %1, i32 %18, i32 %14, double %37)
br label %44
44: ; preds = %42, %40
ret i8* %2
}