void deg2str(string, lstr, deg, ndec) 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
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    %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    12d0 <deg2str+0x180>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
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   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edx,%ebp
movapd %xmm0,%xmm2
movapd %xmm0,(%rsp)
mov    %esi,%r14d
mov    %rdi,%r15
movapd %xmm0,%xmm1
xorpd  0xe89(%rip),%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
movsd  0xe7c(%rip),%xmm1
call   1060 <fmod@plt>
xorpd  %xmm1,%xmm1
ucomisd (%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,(%rsp)
lea    0x4(%rbp),%edx
test   %ebp,%ebp
jle    120b <deg2str+0xbb>
lea    0xe44(%rip),%rsi
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
movapd (%rsp),%xmm0
mov    $0x1,%al
call   1070 <sprintf@plt>
jmp    1235 <deg2str+0xe5>
lea    0xe1f(%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>
movslq %r14d,%rbp
add    $0xffffffffffffffff,%rbp
lea    0x20(%rsp),%rsi
cmp    %eax,%ebp
jle    1259 <deg2str+0x109>
mov    %r15,%rdi
call   1040 <strcpy@plt>
jmp    1269 <deg2str+0x119>
mov    %r15,%rdi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbp,1)
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 %47
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*, ...) @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 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* %44, double %45)
br label %56
47: ; preds = %33
%48 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%49 = load i32, i32* %10
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%52 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%53 = load double, double* %13
%54 = fptosi double %53 to i32
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* %52, i32 %54)
br label %56
56: ; preds = %47, %38
%57 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%58 = call i64 @strlen(i8* %57)
%59 = trunc i64 %58 to i32
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = load i32, i32* %6
%62 = sub nsw i32 %61, 1
%63 = icmp slt i32 %60, %62
br i1 %63, label %64, label %68
64: ; preds = %56
%65 = load i8*, i8** %5
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%67 = call i8* @strcpy(i8* %65, i8* %66)
br label %80
68: ; preds = %56
%69 = load i8*, i8** %5
%70 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%71 = load i32, i32* %6
%72 = sub nsw i32 %71, 1
%73 = sext i32 %72 to i64
%74 = call i8* @strncpy(i8* %69, i8* %70, i64 %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 = %68, %64
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 = trunc i64 %28 to i32
%30 = add nsw i32 %1, -1
%31 = icmp sgt i32 %30, %29
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 = sext i32 %30 to i64
%36 = call i8* @strncpy(i8* dereferenceable(1) %0, i8* %8, i64 %35)
%37 = getelementptr inbounds i8, i8* %0, i64 %35
store i8 0, i8* %37
br label %38
38: ; preds = %34, %32
ret void
}