#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 */
unsigned long pow(int, int);
double convert2gb(unsigned long int total, unsigned long int val) {
  double newval = 0;
  if (total == 0) {
    newval = val / pow(2, 30);
  } else {
    newval = total / pow(2, 30) - val / pow(2, 30);
  }
  return newval;
}


x86 assembly (clang, -O0):
<convert2gb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1187 <convert2gb+0x77>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x2,%edi
mov    $0x1e,%esi
call   1030 <pow@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
movq   %rax,%xmm0
movaps 0xe9e(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xea2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    120f <convert2gb+0xff>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x2,%edi
mov    %edi,-0x48(%rbp)
mov    $0x1e,%esi
mov    %esi,-0x44(%rbp)
call   1030 <pow@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%esi
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
xor    %edx,%edx
mov    %rdx,-0x38(%rbp)
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
call   1030 <pow@plt>
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
div    %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xe11(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe15(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert2gb>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2,%edi
mov    $0x1e,%esi
call   1030 <pow@plt>
mov    %rax,%rcx
test   %rbx,%rbx
je     1147 <convert2gb+0x37>
or     %rbx,%rax
shr    $0x20,%rax
je     115d <convert2gb+0x4d>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rbx
jmp    1165 <convert2gb+0x55>
or     %r14,%rax
shr    $0x20,%rax
je     11bd <convert2gb+0xad>
mov    %r14,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rbx
jmp    1194 <convert2gb+0x84>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ebx
mov    $0x2,%edi
mov    $0x1e,%esi
call   1030 <pow@plt>
mov    %rax,%rcx
or     %r14,%rax
shr    $0x20,%rax
je     118a <convert2gb+0x7a>
mov    %r14,%rax
xor    %edx,%edx
div    %rcx
jmp    1191 <convert2gb+0x81>
mov    %r14d,%eax
xor    %edx,%edx
div    %ecx
sub    %rax,%rbx
movq   %rbx,%xmm1
punpckldq 0xe5f(%rip),%xmm1
subpd  0xe67(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ebx
jmp    1194 <convert2gb+0x84>

LLVM IR (-O0):
define double @convert2gb(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
store i64 %0, i64* %3
store i64 %1, i64* %4
store double 0.000000e+00, double* %5
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i64, i64* %4
%10 = call i64 @pow(i32 2, i32 30)
%11 = udiv i64 %9, %10
%12 = uitofp i64 %11 to double
store double %12, double* %5
br label %22
13: ; preds = %2
%14 = load i64, i64* %3
%15 = call i64 @pow(i32 2, i32 30)
%16 = udiv i64 %14, %15
%17 = load i64, i64* %4
%18 = call i64 @pow(i32 2, i32 30)
%19 = udiv i64 %17, %18
%20 = sub i64 %16, %19
%21 = uitofp i64 %20 to double
store double %21, double* %5
br label %22
22: ; preds = %13, %8
%23 = load double, double* %5
ret double %23
}

LLVM IR (-O2):
define double @convert2gb(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
%4 = tail call i64 @pow(i32 2, i32 30)
br i1 %3, label %5, label %7
5: ; preds = %2
%6 = udiv i64 %1, %4
br label %12
7: ; preds = %2
%8 = udiv i64 %0, %4
%9 = tail call i64 @pow(i32 2, i32 30)
%10 = udiv i64 %1, %9
%11 = sub i64 %8, %10
br label %12
12: ; preds = %7, %5
%13 = phi i64 [ %6, %5 ], [ %11, %7 ]
%14 = uitofp i64 %13 to double
ret double %14
}