void deg2str(string, lstr, deg, ndec) char *string;
int lstr;
double deg;
int ndec;
{
  char degform[8];
  int field;
  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);
  }
  if (strlen(tstring) < (unsigned int)(lstr - 1))
    strcpy(string, tstring);
  else {
    strncpy(string, tstring, (unsigned int)(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
movsd  -0x78(%rbp),%xmm0
mov    $0x1,%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    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
cmp    %rcx,%rax
jae    12a6 <deg2str+0x156>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    12ce <deg2str+0x17e>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
mov    %eax,%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   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edx,%ebx
movapd %xmm0,%xmm2
movapd %xmm0,(%rsp)
mov    %esi,%r15d
mov    %rdi,%r14
movapd %xmm0,%xmm1
xorpd  0xe88(%rip),%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  0xe7b(%rip),%xmm1
call   1060 <fmod@plt>
xorpd  %xmm1,%xmm1
ucomisd (%rsp),%xmm1
jbe    11ad <deg2str+0x5d>
xorpd  0xe53(%rip),%xmm0
movsd  0xe5b(%rip),%xmm2
addsd  %xmm0,%xmm2
movapd %xmm0,%xmm1
cmpnlesd 0xe52(%rip),%xmm1
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,(%rsp)
lea    0x4(%rbx),%edx
test   %ebx,%ebx
jle    120c <deg2str+0xbc>
lea    0xe43(%rip),%rsi
lea    0x18(%rsp),%r12
mov    %r12,%rdi
mov    %ebx,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x20(%rsp),%rdi
mov    %r12,%rsi
movapd (%rsp),%xmm0
mov    $0x1,%al
call   1070 <sprintf@plt>
jmp    1236 <deg2str+0xe6>
lea    0xe1e(%rip),%rsi
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <sprintf@plt>
cvttsd2si (%rsp),%edx
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x20(%rsp),%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%r15d
lea    0x20(%rsp),%rsi
cmp    %r15,%rax
jae    1258 <deg2str+0x108>
mov    %r14,%rdi
call   1040 <strcpy@plt>
jmp    126b <deg2str+0x11b>
mov    %r14,%rdi
mov    %r15,%rdx
call   1030 <strncpy@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 [64 x i8]
%12 = alloca double
%13 = alloca double
store i8* %0, i8** %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
%14 = load double, double* %7
store double %14, double* %12
%15 = load double, double* %12
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load double, double* %12
%19 = fneg double %18
store double %19, double* %12
store double -1.000000e+00, double* %13
br label %21
20: ; preds = %4
store double 1.000000e+00, double* %13
br label %21
21: ; preds = %20, %17
%22 = load double, double* %12
%23 = call double @fmod(double %22, double 3.600000e+02)
store double %23, double* %12
%24 = load double, double* %13
%25 = load double, double* %12
%26 = fmul double %25, %24
store double %26, double* %12
%27 = load double, double* %12
%28 = fcmp ole double %27, -1.800000e+02
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = load double, double* %12
%31 = fadd double %30, 3.600000e+02
store double %31, double* %12
br label %32
32: ; preds = %29, %21
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 4
store i32 %34, i32* %10
%35 = load i32, i32* %8
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %32
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%39 = load i32, i32* %10
%40 = load i32, i32* %8
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %40)
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%44 = load double, double* %12
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* %43, double %44)
br label %55
46: ; preds = %32
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* %10
%49 = call i32 (i8*, i8*, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%51 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%52 = load double, double* %12
%53 = fptosi double %52 to i32
%54 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* %51, i32 %53)
br label %55
55: ; preds = %46, %37
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%57 = call i64 @strlen(i8* %56)
%58 = load i32, i32* %6
%59 = sub nsw i32 %58, 1
%60 = zext i32 %59 to i64
%61 = icmp ult i64 %57, %60
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = load i8*, i8** %5
%64 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%65 = call i8* @strcpy(i8* %63, i8* %64)
br label %78
66: ; preds = %55
%67 = load i8*, i8** %5
%68 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%69 = load i32, i32* %6
%70 = sub nsw i32 %69, 1
%71 = zext i32 %70 to i64
%72 = call i8* @strncpy(i8* %67, i8* %68, i64 %71)
%73 = load i8*, i8** %5
%74 = load i32, i32* %6
%75 = sub nsw i32 %74, 1
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
store i8 0, i8* %77
br label %78
78: ; preds = %66, %62
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 %23
20: ; preds = %4
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %3)
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* %7, double %17)
br label %27
23: ; preds = %4
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%25 = fptosi double %17 to i32
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* %7, i32 %25)
br label %27
27: ; preds = %23, %20
%28 = call i64 @strlen(i8* %8)
%29 = add nsw i32 %1, -1
%30 = zext i32 %29 to i64
%31 = icmp ult i64 %28, %30
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* %8)
br label %38
34: ; preds = %27
%35 = call i8* @strncpy(i8* dereferenceable(1) %0, i8* %8, i64 %30)
%36 = sext i32 %29 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %34, %32
ret void
}