#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*/ sprintf(char *, char *, ...);
char *outfmt(char format, double b) {
  static char obuf[50];
  double giga = 1024.0 * 1024.0 * 1024.0;
  double mega = 1024.0 * 1024.0;
  double kilo = 1024.0;
  if (format == 'A') {
    if (b >= giga)
      format = 'G';
    else if (b >= mega)
      format = 'M';
    else if (b >= kilo)
      format = 'K';
    else
      format = 'B';
  }
  switch (format) {
  case 'G':
    sprintf(obuf, "%.3f GB", b / giga);
    break;
  case 'M':
    sprintf(obuf, "%.3f MB", b / mega);
    break;
  case 'K':
    sprintf(obuf, "%.3f KB", b / kilo);
    break;
  case 'B':
    sprintf(obuf, "%4f B", b);
    break;
  case 'g':
    sprintf(obuf, "%.3f Gbit", b * 8.0 / giga);
    break;
  case 'm':
    sprintf(obuf, "%.3f Mbit", b * 8.0 / mega);
    break;
  case 'k':
    sprintf(obuf, "%.3f Kbit", b * 8.0 / kilo);
    break;
  case 'b':
    sprintf(obuf, "%4f b", b * 8.0);
    break;
  default:
    sprintf(obuf, "default..........");
  }
  return obuf;
}


x86 assembly (clang, -O0):
<outfmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  0xee5(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xebb(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jne    11b5 <outfmt+0xa5>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1170 <outfmt+0x60>
movb   $0x47,-0x1(%rbp)
jmp    11b0 <outfmt+0xa0>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1189 <outfmt+0x79>
movb   $0x4d,-0x1(%rbp)
jmp    11ab <outfmt+0x9b>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11a2 <outfmt+0x92>
movb   $0x4b,-0x1(%rbp)
jmp    11a6 <outfmt+0x96>
movb   $0x42,-0x1(%rbp)
jmp    11ab <outfmt+0x9b>
jmp    11b0 <outfmt+0xa0>
jmp    11b5 <outfmt+0xa5>
movsbl -0x1(%rbp),%eax
add    $0xffffffbe,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x2b,%eax
ja     1315 <outfmt+0x205>
mov    -0x30(%rbp),%rax
lea    0xe4a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
lea    0x2e50(%rip),%rdi
lea    0xed9(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
lea    0x2e2c(%rip),%rdi
lea    0xebd(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  -0x10(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
lea    0x2e08(%rip),%rdi
lea    0xea1(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  -0x10(%rbp),%xmm0
lea    0x2de9(%rip),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  0xda6(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
lea    0x2dbd(%rip),%rdi
lea    0xe64(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  0xd7a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
lea    0x2d91(%rip),%rdi
lea    0xe42(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  0xd4e(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
lea    0x2d65(%rip),%rdi
lea    0xe20(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
movsd  0xd22(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
lea    0x2d3e(%rip),%rdi
lea    0xe03(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    132a <outfmt+0x21a>
lea    0x2d24(%rip),%rdi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
lea    0x2d0f(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outfmt>:
push   %rax
cmp    $0x41,%dil
jne    113e <outfmt+0x2e>
ucomisd 0xee1(%rip),%xmm0
jae    116d <outfmt+0x5d>
ucomisd 0xedf(%rip),%xmm0
jae    1188 <outfmt+0x78>
xor    %eax,%eax
ucomisd 0xedb(%rip),%xmm0
setae  %al
lea    (%rax,%rax,8),%edi
add    $0x42,%edi
movsbl %dil,%eax
add    $0xffffffbe,%eax
cmp    $0x2b,%eax
ja     11a3 <outfmt+0x93>
lea    0xee7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0x2edf(%rip),%rdi
lea    0xf98(%rip),%rsi
jmp    124f <outfmt+0x13f>
mulsd  0xebb(%rip),%xmm0
lea    0x2ec4(%rip),%rdi
lea    0xf65(%rip),%rsi
jmp    124f <outfmt+0x13f>
mulsd  0xe98(%rip),%xmm0
lea    0x2ea9(%rip),%rdi
lea    0xf52(%rip),%rsi
jmp    124f <outfmt+0x13f>
movupd 0xf7f(%rip),%xmm0
movapd %xmm0,0x2e8d(%rip)
movw   $0x2e,0x2e94(%rip)
jmp    1256 <outfmt+0x146>
mulsd  0xe57(%rip),%xmm0
lea    0x2e70(%rip),%rdi
lea    0xf21(%rip),%rsi
jmp    124f <outfmt+0x13f>
mulsd  0xe37(%rip),%xmm0
lea    0x2e58(%rip),%rdi
lea    0xf35(%rip),%rsi
jmp    124f <outfmt+0x13f>
mulsd  0xe1f(%rip),%xmm0
mulsd  0xe2f(%rip),%xmm0
lea    0x2e38(%rip),%rdi
lea    0xef7(%rip),%rsi
jmp    124f <outfmt+0x13f>
mulsd  0xdff(%rip),%xmm0
mulsd  0xdff(%rip),%xmm0
lea    0x2e18(%rip),%rdi
lea    0xeeb(%rip),%rsi
jmp    124f <outfmt+0x13f>
mulsd  0xddf(%rip),%xmm0
mulsd  0xde7(%rip),%xmm0
lea    0x2df8(%rip),%rdi
lea    0xec1(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
lea    0x2de3(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@outfmt.obuf = internal global [50 x i8] zeroinitializer
@.str = [8 x i8] c"%.3f GB\00"
@.str.1 = [8 x i8] c"%.3f MB\00"
@.str.2 = [8 x i8] c"%.3f KB\00"
@.str.3 = [6 x i8] c"%4f B\00"
@.str.4 = [10 x i8] c"%.3f Gbit\00"
@.str.5 = [10 x i8] c"%.3f Mbit\00"
@.str.6 = [10 x i8] c"%.3f Kbit\00"
@.str.7 = [6 x i8] c"%4f b\00"
@.str.8 = [18 x i8] c"default..........\00"
define i8* @outfmt(i8 signext %0, double %1) {
%3 = alloca i8
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i8 %0, i8* %3
store double %1, double* %4
store double 0x41D0000000000000, double* %5
store double 0x4130000000000000, double* %6
store double 1.024000e+03, double* %7
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 65
br i1 %10, label %11, label %30
11: ; preds = %2
%12 = load double, double* %4
%13 = load double, double* %5
%14 = fcmp oge double %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i8 71, i8* %3
br label %29
16: ; preds = %11
%17 = load double, double* %4
%18 = load double, double* %6
%19 = fcmp oge double %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i8 77, i8* %3
br label %28
21: ; preds = %16
%22 = load double, double* %4
%23 = load double, double* %7
%24 = fcmp oge double %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i8 75, i8* %3
br label %27
26: ; preds = %21
store i8 66, i8* %3
br label %27
27: ; preds = %26, %25
br label %28
28: ; preds = %27, %20
br label %29
29: ; preds = %28, %15
br label %30
30: ; preds = %29, %2
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
switch i32 %32, label %73 [
i32 71, label %33
i32 77, label %38
i32 75, label %43
i32 66, label %48
i32 103, label %51
i32 109, label %57
i32 107, label %63
i32 98, label %69
]
33: ; preds = %30
%34 = load double, double* %4
%35 = load double, double* %5
%36 = fdiv double %34, %35
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %36)
br label %75
38: ; preds = %30
%39 = load double, double* %4
%40 = load double, double* %6
%41 = fdiv double %39, %40
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %41)
br label %75
43: ; preds = %30
%44 = load double, double* %4
%45 = load double, double* %7
%46 = fdiv double %44, %45
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %46)
br label %75
48: ; preds = %30
%49 = load double, double* %4
%50 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %49)
br label %75
51: ; preds = %30
%52 = load double, double* %4
%53 = fmul double %52, 8.000000e+00
%54 = load double, double* %5
%55 = fdiv double %53, %54
%56 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %55)
br label %75
57: ; preds = %30
%58 = load double, double* %4
%59 = fmul double %58, 8.000000e+00
%60 = load double, double* %6
%61 = fdiv double %59, %60
%62 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %61)
br label %75
63: ; preds = %30
%64 = load double, double* %4
%65 = fmul double %64, 8.000000e+00
%66 = load double, double* %7
%67 = fdiv double %65, %66
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), double %67)
br label %75
69: ; preds = %30
%70 = load double, double* %4
%71 = fmul double %70, 8.000000e+00
%72 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), double %71)
br label %75
73: ; preds = %30
%74 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %75
75: ; preds = %73, %69, %63, %57, %51, %48, %43, %38, %33
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0)
}

LLVM IR (-O2):
@outfmt.obuf = internal global [50 x i8] zeroinitializer
@.str = [8 x i8] c"%.3f GB\00"
@.str.1 = [8 x i8] c"%.3f MB\00"
@.str.2 = [8 x i8] c"%.3f KB\00"
@.str.3 = [6 x i8] c"%4f B\00"
@.str.4 = [10 x i8] c"%.3f Gbit\00"
@.str.5 = [10 x i8] c"%.3f Mbit\00"
@.str.6 = [10 x i8] c"%.3f Kbit\00"
@.str.7 = [6 x i8] c"%4f b\00"
@.str.8 = [18 x i8] c"default..........\00"
define i8* @outfmt(i8 signext %0, double %1) {
%3 = icmp eq i8 %0, 65
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = fcmp ult double %1, 0x41D0000000000000
br i1 %5, label %6, label %14
6: ; preds = %4
%7 = fcmp ult double %1, 0x4130000000000000
br i1 %7, label %8, label %17
8: ; preds = %6
%9 = fcmp ult double %1, 1.024000e+03
%10 = select i1 %9, i8 66, i8 75
br label %11
11: ; preds = %8, %2
%12 = phi i8 [ %0, %2 ], [ %10, %8 ]
%13 = sext i8 %12 to i32
switch i32 %13, label %40 [
i32 71, label %14
i32 77, label %17
i32 75, label %20
i32 66, label %23
i32 103, label %25
i32 109, label %29
i32 107, label %33
i32 98, label %37
]
14: ; preds = %4, %11
%15 = fmul double %1, 0x3E10000000000000
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), double %15)
br label %41
17: ; preds = %6, %11
%18 = fmul double %1, 0x3EB0000000000000
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), double %18)
br label %41
20: ; preds = %11
%21 = fmul double %1, 0x3F50000000000000
%22 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), double %21)
br label %41
23: ; preds = %11
%24 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %1)
br label %41
25: ; preds = %11
%26 = fmul double %1, 8.000000e+00
%27 = fmul double %26, 0x3E10000000000000
%28 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), double %27)
br label %41
29: ; preds = %11
%30 = fmul double %1, 8.000000e+00
%31 = fmul double %30, 0x3EB0000000000000
%32 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), double %31)
br label %41
33: ; preds = %11
%34 = fmul double %1, 8.000000e+00
%35 = fmul double %34, 0x3F50000000000000
%36 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), double %35)
br label %41
37: ; preds = %11
%38 = fmul double %1, 8.000000e+00
%39 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), double %38)
br label %41
40: ; preds = %11
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(18) getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0), i8* align 1 dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i64 18, i1 false)
br label %41
41: ; preds = %40, %37, %33, %29, %25, %23, %20, %17, %14
ret i8* getelementptr inbounds ([50 x i8], [50 x i8]* @outfmt.obuf, i64 0, i64 0)
}