#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 double_input(int /*<<< orphan*/, int, char *);
int int_input(int, int, char *);
int /*<<< orphan*/ printf(char *, ...);
void dms_to_dd(void) {
  int dms_deg, dms_min;
  char positive = 1;
  double dms_sec;
  double result;
  char *input;
  printf(
      "Converts DMS (Degrees Minutes Seconds) to DD.DDD (Decimal degrees)\n");
  input = "Enter DMS degrees (integer): ";
  dms_deg = int_input(-180, 180, input);
  input = "Enter DMS minutes (integer): ";
  dms_min = int_input(0, 60, input);
  input = "Enter DMS seconds (real): ";
  dms_sec = double_input(0, 60, input);
  if (dms_deg < 0) {
    dms_deg *= -1;
    positive = 0;
  }
  result = (dms_deg + ((dms_min + (dms_sec / 60)) / 60));
  if (positive == 0) {
    result *= -1;
  }
  printf("\nResult in decimal degrees: %lf°\n\n", result);
}


x86 assembly (clang, -O0):
<dms_to_dd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movb   $0x1,-0x9(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf03(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    $0xffffff4c,%edi
mov    $0xb4,%esi
call   1050 <int_input@plt>
mov    %eax,-0x4(%rbp)
lea    0xf00(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
xor    %edi,%edi
mov    $0x3c,%esi
call   1050 <int_input@plt>
mov    %eax,-0x8(%rbp)
lea    0xf00(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
xor    %edi,%edi
mov    $0x3c,%esi
call   1030 <double_input@plt>
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11be <dms_to_dd+0x8e>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movb   $0x0,-0x9(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  0xe2b(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
movsd  0xe1b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    1211 <dms_to_dd+0xe1>
movsd  0xe01(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe8e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dms_to_dd>:
push   %rbp
push   %rbx
push   %rax
lea    0xf51(%rip),%rdi
call   1030 <puts@plt>
lea    0xeca(%rip),%rdx
mov    $0xffffff4c,%edi
mov    $0xb4,%esi
call   1060 <int_input@plt>
mov    %eax,%ebx
lea    0xed0(%rip),%rdx
xor    %edi,%edi
mov    $0x3c,%esi
call   1060 <int_input@plt>
mov    %eax,%ebp
lea    0xed9(%rip),%rdx
xor    %edi,%edi
mov    $0x3c,%esi
call   1040 <double_input@plt>
mov    %ebx,%eax
neg    %eax
cmovs  %ebx,%eax
cvtsi2sd %eax,%xmm1
cvtsi2sd %ebp,%xmm2
movsd  0xe5a(%rip),%xmm3
divsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
test   %ebx,%ebx
jns    11c2 <dms_to_dd+0x82>
xorpd  0xe4e(%rip),%xmm0
lea    0xeae(%rip),%rdi
mov    $0x1,%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [68 x i8] c"Converts DMS (Degrees Minutes Seconds) to DD.DDD (Decimal degrees)\0A\00"
@.str.1 = [30 x i8] c"Enter DMS degrees (integer): \00"
@.str.2 = [30 x i8] c"Enter DMS minutes (integer): \00"
@.str.3 = [27 x i8] c"Enter DMS seconds (real): \00"
@.str.4 = [36 x i8] c"\0AResult in decimal degrees: %lf\C2\B0\0A\0A\00"
define void @dms_to_dd() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca double
%5 = alloca double
%6 = alloca i8*
store i8 1, i8* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @int_input(i32 -180, i32 180, i8* %8)
store i32 %9, i32* %1
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @int_input(i32 0, i32 60, i8* %10)
store i32 %11, i32* %2
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8** %6
%12 = load i8*, i8** %6
%13 = call double @double_input(i32 0, i32 60, i8* %12)
store double %13, double* %4
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = load i32, i32* %1
%18 = mul nsw i32 %17, -1
store i32 %18, i32* %1
store i8 0, i8* %3
br label %19
19: ; preds = %16, %0
%20 = load i32, i32* %1
%21 = sitofp i32 %20 to double
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to double
%24 = load double, double* %4
%25 = fdiv double %24, 6.000000e+01
%26 = fadd double %23, %25
%27 = fdiv double %26, 6.000000e+01
%28 = fadd double %21, %27
store double %28, double* %5
%29 = load i8, i8* %3
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %19
%33 = load double, double* %5
%34 = fmul double %33, -1.000000e+00
store double %34, double* %5
br label %35
35: ; preds = %32, %19
%36 = load double, double* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %36)
ret void
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Enter DMS degrees (integer): \00"
@.str.2 = [30 x i8] c"Enter DMS minutes (integer): \00"
@.str.3 = [27 x i8] c"Enter DMS seconds (real): \00"
@.str.4 = [36 x i8] c"\0AResult in decimal degrees: %lf\C2\B0\0A\0A\00"
@str = [67 x i8] c"Converts DMS (Degrees Minutes Seconds) to DD.DDD (Decimal degrees)\00"
define void @dms_to_dd() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @int_input(i32 -180, i32 180, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @int_input(i32 0, i32 60, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call double @double_input(i32 0, i32 60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp slt i32 %2, 0
%6 = sub nsw i32 0, %2
%7 = select i1 %5, i32 %6, i32 %2
%8 = sitofp i32 %7 to double
%9 = sitofp i32 %3 to double
%10 = fdiv double %4, 6.000000e+01
%11 = fadd double %10, %9
%12 = fdiv double %11, 6.000000e+01
%13 = fadd double %12, %8
%14 = fneg double %13
%15 = select i1 %5, double %14, double %13
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %15)
ret void
}