#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 fmod(double, double);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void deg2str(char *string, int lstr, double deg, int ndec) {
  char degform[8];
  int field, ltstr;
  char tstring[64];
  double deg1;
  double dsgn;
  deg1 = deg;
  if (deg1 < 0.0) {
    deg1 = -deg1;
    dsgn = -1.0;
  } else {
    dsgn = 1.0;
  }
  deg1 = fmod(deg1, 360.0);
  deg1 *= dsgn;
  if (deg1 <= -180.0) {
    deg1 = deg1 + 360.0;
  }
  field = ndec + 4;
  if (ndec > 0) {
    sprintf(degform, "%%%d.%df", field, ndec);
    sprintf(tstring, degform, deg1);
  } else {
    sprintf(degform, "%%%4d", field);
    sprintf(tstring, degform, (int)deg1);
  }
  ltstr = (int)strlen(tstring);
  if (ltstr < lstr - 1) {
    strcpy(string, tstring);
  } else {
    strncpy(string, tstring, lstr - 1);
    string[lstr - 1] = 0;
  }
  return;
}


x86 assembly (clang, -O0):
<deg2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x78(%rbp),%xmm0
jbe    11b5 <deg2str+0x65>
movsd  -0x78(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xe5d(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
jmp    11c2 <deg2str+0x72>
movsd  0xe43(%rip),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
call   1060 <fmod@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x80(%rbp),%xmm0
mulsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  0xe20(%rip),%xmm0
ucomisd -0x78(%rbp),%xmm0
jb     120d <deg2str+0xbd>
movsd  0xe15(%rip),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1251 <deg2str+0x101>
lea    -0x24(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x24(%rbp),%rsi
cvttsd2si -0x78(%rbp),%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    127a <deg2str+0x12a>
lea    -0x24(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x24(%rbp),%rsi
cvttsd2si -0x78(%rbp),%edx
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12a9 <deg2str+0x159>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    12cd <deg2str+0x17d>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deg2str>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %edx,%ebp
movapd %xmm0,%xmm2
movapd %xmm0,0x10(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
movapd %xmm0,%xmm1
xorpd  0xe8a(%rip),%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  0xe7d(%rip),%xmm1
call   1060 <fmod@plt>
xorpd  %xmm1,%xmm1
ucomisd 0x10(%rsp),%xmm1
jbe    11ac <deg2str+0x5c>
xorpd  0xe54(%rip),%xmm0
movsd  0xe5c(%rip),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm0,%xmm1
cmpnlesd 0xe53(%rip),%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
lea    0x4(%rbp),%edx
test   %ebp,%ebp
jle    11f5 <deg2str+0xa5>
lea    0xe43(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
jmp    1208 <deg2str+0xb8>
lea    0xe35(%rip),%rsi
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1070 <sprintf@plt>
cvttsd2si 0x10(%rsp),%edx
lea    0x20(%rsp),%rbp
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
movslq %r14d,%rbp
add    $0xffffffffffffffff,%rbp
lea    0x20(%rsp),%rsi
cmp    %eax,%ebp
jle    1244 <deg2str+0xf4>
mov    %rbx,%rdi
call   1040 <strcpy@plt>
jmp    1252 <deg2str+0x102>
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%rbp,1)
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%%%d.%df\00"
@.str.1 = [6 x i8] c"%%%4d\00"
define void @deg2str(i8* %0, i32 %1, double %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca [8 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [64 x i8]
%13 = alloca double
%14 = alloca double
store i8* %0, i8** %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
%15 = load double, double* %7
store double %15, double* %13
%16 = load double, double* %13
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load double, double* %13
%20 = fneg double %19
store double %20, double* %13
store double -1.000000e+00, double* %14
br label %22
21: ; preds = %4
store double 1.000000e+00, double* %14
br label %22
22: ; preds = %21, %18
%23 = load double, double* %13
%24 = call double @fmod(double %23, double 3.600000e+02)
store double %24, double* %13
%25 = load double, double* %14
%26 = load double, double* %13
%27 = fmul double %26, %25
store double %27, double* %13
%28 = load double, double* %13
%29 = fcmp ole double %28, -1.800000e+02
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load double, double* %13
%32 = fadd double %31, 3.600000e+02
store double %32, double* %13
br label %33
33: ; preds = %30, %22
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 4
store i32 %35, i32* %10
%36 = load i32, i32* %8
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %33
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* %10
%41 = load i32, i32* %8
%42 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %40, i32 %41)
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%45 = load double, double* %13
%46 = fptosi double %45 to i32
%47 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %43, i8* %44, i32 %46)
br label %57
48: ; preds = %33
%49 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%50 = load i32, i32* %10
%51 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%53 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%54 = load double, double* %13
%55 = fptosi double %54 to i32
%56 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %52, i8* %53, i32 %55)
br label %57
57: ; preds = %48, %38
%58 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%59 = call i64 @strlen(i8* %58)
%60 = trunc i64 %59 to i32
store i32 %60, i32* %11
%61 = load i32, i32* %11
%62 = load i32, i32* %6
%63 = sub nsw i32 %62, 1
%64 = icmp slt i32 %61, %63
br i1 %64, label %65, label %69
65: ; preds = %57
%66 = load i8*, i8** %5
%67 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%68 = call i32 @strcpy(i8* %66, i8* %67)
br label %80
69: ; preds = %57
%70 = load i8*, i8** %5
%71 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%72 = load i32, i32* %6
%73 = sub nsw i32 %72, 1
%74 = call i32 @strncpy(i8* %70, i8* %71, i32 %73)
%75 = load i8*, i8** %5
%76 = load i32, i32* %6
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %75, i64 %78
store i8 0, i8* %79
br label %80
80: ; preds = %69, %65
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%%%d.%df\00"
@.str.1 = [6 x i8] c"%%%4d\00"
define void @deg2str(i8* %0, i32 %1, double %2, i32 %3) {
%5 = alloca [8 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%9 = fcmp olt double %2, 0.000000e+00
%10 = fneg double %2
%11 = select i1 %9, double %10, double %2
%12 = tail call double @fmod(double %11, double 3.600000e+02)
%13 = fneg double %12
%14 = select i1 %9, double %13, double %12
%15 = fcmp ugt double %14, -1.800000e+02
%16 = fadd double %14, 3.600000e+02
%17 = select i1 %15, double %14, double %16
%18 = add nsw i32 %3, 4
%19 = icmp sgt i32 %3, 0
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %3)
br label %24
22: ; preds = %4
%23 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %24
24: ; preds = %22, %20
%25 = fptosi double %17 to i32
%26 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* %7, i32 %25)
%27 = call i64 @strlen(i8* %8)
%28 = trunc i64 %27 to i32
%29 = add nsw i32 %1, -1
%30 = icmp sgt i32 %29, %28
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @strcpy(i8* %0, i8* %8)
br label %37
33: ; preds = %24
%34 = call i32 @strncpy(i8* %0, i8* %8, i32 %29)
%35 = sext i32 %29 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %33, %31
ret void
}