#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 */
int /*<<< orphan*/ strcpy(char *, char *);
long double to_unit(char *unit, long double bval, long double gval, int mode) {
  long double tval;
  if (bval < 1024 && gval == 0) {
    strcpy(unit, "B");
    return bval;
  } else if (bval < 1048576 && gval == 0) {
    strcpy(unit, "KB");
    tval = (bval / 1024);
    return tval;
  } else if (bval < 1073741824 && gval == 0) {
    strcpy(unit, "MB");
    tval = (bval / 1048576);
    return tval;
  } else {
    strcpy(unit, "GB");
    tval = gval;
    tval += (bval / (long double)1073741824);
    return (tval);
  }
}


x86 assembly (clang, -O0):
<to_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
fldt   0x20(%rbp)
fldt   0x10(%rbp)
mov    %rdi,-0x18(%rbp)
fstpt  -0x30(%rbp)
fstpt  -0x40(%rbp)
mov    %esi,-0x44(%rbp)
fldt   -0x30(%rbp)
flds   0xecc(%rip)
fucomip %st(1),%st
fstp   %st(0)
jbe    117a <to_unit+0x6a>
jmp    1143 <to_unit+0x33>
fldt   -0x40(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    117a <to_unit+0x6a>
jp     117a <to_unit+0x6a>
jmp    115f <to_unit+0x4f>
mov    -0x18(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1030 <strcpy@plt>
fldt   -0x30(%rbp)
fstpt  -0x10(%rbp)
jmp    1263 <to_unit+0x153>
fldt   -0x30(%rbp)
flds   0xe81(%rip)
fucomip %st(1),%st
fstp   %st(0)
jbe    11d7 <to_unit+0xc7>
jmp    1192 <to_unit+0x82>
fldt   -0x40(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11d7 <to_unit+0xc7>
jp     11d7 <to_unit+0xc7>
jmp    11ae <to_unit+0x9e>
mov    -0x18(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1030 <strcpy@plt>
fldt   -0x30(%rbp)
flds   0xe39(%rip)
fdivrp %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
fstpt  -0x10(%rbp)
jmp    1263 <to_unit+0x153>
fldt   -0x30(%rbp)
flds   0xe28(%rip)
fucomip %st(1),%st
fstp   %st(0)
jbe    1234 <to_unit+0x124>
jmp    11ef <to_unit+0xdf>
fldt   -0x40(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1234 <to_unit+0x124>
jp     1234 <to_unit+0x124>
jmp    120b <to_unit+0xfb>
mov    -0x18(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1030 <strcpy@plt>
fldt   -0x30(%rbp)
flds   0xde0(%rip)
fdivrp %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
fstpt  -0x10(%rbp)
jmp    1263 <to_unit+0x153>
mov    -0x18(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1030 <strcpy@plt>
fldt   -0x40(%rbp)
fstpt  -0x60(%rbp)
fldt   -0x30(%rbp)
flds   0xdb5(%rip)
fdivrp %st,%st(1)
fldt   -0x60(%rbp)
faddp  %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_unit>:
sub    $0x18,%rsp
fldt   0x30(%rsp)
fldt   0x20(%rsp)
flds   0xede(%rip)
fucomip %st(1),%st
fld    %st(0)
fstpt  (%rsp)
jbe    114f <to_unit+0x3f>
fldz
fxch   %st(2)
fucomi %st(2),%st
fstp   %st(2)
jne    114f <to_unit+0x3f>
jp     114f <to_unit+0x3f>
fstp   %st(0)
fstp   %st(0)
lea    0xedd(%rip),%rsi
call   1030 <strcpy@plt>
fldt   (%rsp)
add    $0x18,%rsp
ret
flds   0xeaf(%rip)
fucomip %st(1),%st
jbe    1183 <to_unit+0x73>
fldz
fxch   %st(2)
fucomi %st(2),%st
fstp   %st(2)
jne    1183 <to_unit+0x73>
jp     1183 <to_unit+0x73>
fstp   %st(0)
fstp   %st(0)
lea    0xea8(%rip),%rsi
call   1030 <strcpy@plt>
fldt   (%rsp)
fmuls  0xe96(%rip)
add    $0x18,%rsp
ret
flds   0xe7f(%rip)
fucomip %st(1),%st
fstp   %st(0)
jbe    11b7 <to_unit+0xa7>
fldz
fxch   %st(1)
fucomi %st(1),%st
fstp   %st(1)
jne    11b7 <to_unit+0xa7>
jp     11b7 <to_unit+0xa7>
fstp   %st(0)
lea    0xe77(%rip),%rsi
call   1030 <strcpy@plt>
fldt   (%rsp)
fmuls  0xe5e(%rip)
add    $0x18,%rsp
ret
lea    0xe60(%rip),%rsi
fstpt  0xc(%rsp)
call   1030 <strcpy@plt>
fldt   (%rsp)
fmuls  0xe3c(%rip)
fldt   0xc(%rsp)
faddp  %st,%st(1)
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"KB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
define x86_fp80 @to_unit(i8* %0, x86_fp80 %1, x86_fp80 %2, i32 %3) {
%5 = alloca x86_fp80
%6 = alloca i8*
%7 = alloca x86_fp80
%8 = alloca x86_fp80
%9 = alloca i32
%10 = alloca x86_fp80
store i8* %0, i8** %6
store x86_fp80 %1, x86_fp80* %7
store x86_fp80 %2, x86_fp80* %8
store i32 %3, i32* %9
%11 = load x86_fp80, x86_fp80* %7
%12 = fcmp olt x86_fp80 %11, 0xK40098000000000000000
br i1 %12, label %13, label %20
13: ; preds = %4
%14 = load x86_fp80, x86_fp80* %8
%15 = fcmp oeq x86_fp80 %14, 0xK00000000000000000000
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %6
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load x86_fp80, x86_fp80* %7
store x86_fp80 %19, x86_fp80* %5
br label %53
20: ; preds = %13, %4
%21 = load x86_fp80, x86_fp80* %7
%22 = fcmp olt x86_fp80 %21, 0xK40138000000000000000
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load x86_fp80, x86_fp80* %8
%25 = fcmp oeq x86_fp80 %24, 0xK00000000000000000000
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = load x86_fp80, x86_fp80* %7
%30 = fdiv x86_fp80 %29, 0xK40098000000000000000
store x86_fp80 %30, x86_fp80* %10
%31 = load x86_fp80, x86_fp80* %10
store x86_fp80 %31, x86_fp80* %5
br label %53
32: ; preds = %23, %20
%33 = load x86_fp80, x86_fp80* %7
%34 = fcmp olt x86_fp80 %33, 0xK401D8000000000000000
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = load x86_fp80, x86_fp80* %8
%37 = fcmp oeq x86_fp80 %36, 0xK00000000000000000000
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i8*, i8** %6
%40 = call i32 @strcpy(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%41 = load x86_fp80, x86_fp80* %7
%42 = fdiv x86_fp80 %41, 0xK40138000000000000000
store x86_fp80 %42, x86_fp80* %10
%43 = load x86_fp80, x86_fp80* %10
store x86_fp80 %43, x86_fp80* %5
br label %53
44: ; preds = %35, %32
%45 = load i8*, i8** %6
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = load x86_fp80, x86_fp80* %8
store x86_fp80 %47, x86_fp80* %10
%48 = load x86_fp80, x86_fp80* %7
%49 = fdiv x86_fp80 %48, 0xK401D8000000000000000
%50 = load x86_fp80, x86_fp80* %10
%51 = fadd x86_fp80 %50, %49
store x86_fp80 %51, x86_fp80* %10
%52 = load x86_fp80, x86_fp80* %10
store x86_fp80 %52, x86_fp80* %5
br label %53
53: ; preds = %44, %38, %26, %16
%54 = load x86_fp80, x86_fp80* %5
ret x86_fp80 %54
}

LLVM IR (-O2):
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"KB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
define x86_fp80 @to_unit(i8* %0, x86_fp80 %1, x86_fp80 %2, i32 %3) {
%5 = fcmp olt x86_fp80 %1, 0xK40098000000000000000
%6 = fcmp oeq x86_fp80 %2, 0xK00000000000000000000
%7 = and i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %26
10: ; preds = %4
%11 = fcmp olt x86_fp80 %1, 0xK40138000000000000000
%12 = and i1 %11, %6
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = fmul x86_fp80 %1, 0xK3FF58000000000000000
br label %26
16: ; preds = %10
%17 = fcmp olt x86_fp80 %1, 0xK401D8000000000000000
%18 = and i1 %17, %6
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = fmul x86_fp80 %1, 0xK3FEB8000000000000000
br label %26
22: ; preds = %16
%23 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = fmul x86_fp80 %1, 0xK3FE18000000000000000
%25 = fadd x86_fp80 %24, %2
br label %26
26: ; preds = %22, %19, %13, %8
%27 = phi x86_fp80 [ %1, %8 ], [ %15, %13 ], [ %21, %19 ], [ %25, %22 ]
ret x86_fp80 %27
}