#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 */
scalar_t__ strcasecmp(char *, char *);
double strtod(char *, char **);
int get_rate(unsigned *rate, char *str) {
  char *p;
  double bps = strtod(str, &p);
  if (p == str)
    return -1;
  if (*p) {
    if (strcasecmp(p, "kbps") == 0)
      bps *= 1024;
    else if (strcasecmp(p, "mbps") == 0)
      bps *= 1024 * 1024;
    else if (strcasecmp(p, "mbit") == 0)
      bps *= 1024 * 1024 / 8;
    else if (strcasecmp(p, "kbit") == 0)
      bps *= 1024 / 8;
    else if (strcasecmp(p, "bps") != 0)
      return -1;
  } else
    bps /= 8;
  *rate = bps;
  return 0;
}


x86 assembly (clang, -O0):
<get_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    115c <get_rate+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <get_rate+0x177>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     126c <get_rate+0x14c>
mov    -0x20(%rbp),%rdi
lea    0xeb4(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    119a <get_rate+0x7a>
movsd  0xe95(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1267 <get_rate+0x147>
mov    -0x20(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11cb <get_rate+0xab>
movsd  0xe5c(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1262 <get_rate+0x142>
mov    -0x20(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11fc <get_rate+0xdc>
movsd  0xe23(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    125d <get_rate+0x13d>
mov    -0x20(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    122d <get_rate+0x10d>
movsd  0xdea(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1258 <get_rate+0x138>
mov    -0x20(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     1253 <get_rate+0x133>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <get_rate+0x177>
jmp    1258 <get_rate+0x138>
jmp    125d <get_rate+0x13d>
jmp    1262 <get_rate+0x142>
jmp    1267 <get_rate+0x147>
jmp    1282 <get_rate+0x162>
movsd  -0x28(%rbp),%xmm0
movsd  0xd87(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
call   1040 <strtod@plt>
mov    0x10(%rsp),%rbx
mov    $0xffffffff,%r15d
cmp    %rbp,%rbx
je     121b <get_rate+0xfb>
cmpb   $0x0,(%rbx)
je     11c8 <get_rate+0xa8>
movsd  %xmm0,0x8(%rsp)
lea    0xec5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11d2 <get_rate+0xb2>
lea    0xeb6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11e2 <get_rate+0xc2>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11f2 <get_rate+0xd2>
lea    0xe98(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1202 <get_rate+0xe2>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    121b <get_rate+0xfb>
movsd  0x8(%rsp),%xmm0
jmp    1210 <get_rate+0xf0>
mulsd  0xe50(%rip),%xmm0
jmp    1210 <get_rate+0xf0>
movsd  0x8(%rsp),%xmm0
mulsd  0xe38(%rip),%xmm0
jmp    1210 <get_rate+0xf0>
movsd  0x8(%rsp),%xmm0
mulsd  0xe20(%rip),%xmm0
jmp    1210 <get_rate+0xf0>
movsd  0x8(%rsp),%xmm0
mulsd  0xe08(%rip),%xmm0
jmp    1210 <get_rate+0xf0>
movsd  0x8(%rsp),%xmm0
mulsd  0xdf0(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"kbps\00"
@.str.1 = [5 x i8] c"mbps\00"
@.str.2 = [5 x i8] c"mbit\00"
@.str.3 = [5 x i8] c"kbit\00"
@.str.4 = [4 x i8] c"bps\00"
define i32 @get_rate(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call double @strtod(i8* %8, i8** %6)
store double %9, double* %7
%10 = load i8*, i8** %6
%11 = load i8*, i8** %5
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %63
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %56
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = call i64 @strcasecmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load double, double* %7
%24 = fmul double %23, 1.024000e+03
store double %24, double* %7
br label %55
25: ; preds = %18
%26 = load i8*, i8** %6
%27 = call i64 @strcasecmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load double, double* %7
%31 = fmul double %30, 0x4130000000000000
store double %31, double* %7
br label %54
32: ; preds = %25
%33 = load i8*, i8** %6
%34 = call i64 @strcasecmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load double, double* %7
%38 = fmul double %37, 1.310720e+05
store double %38, double* %7
br label %53
39: ; preds = %32
%40 = load i8*, i8** %6
%41 = call i64 @strcasecmp(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load double, double* %7
%45 = fmul double %44, 1.280000e+02
store double %45, double* %7
br label %52
46: ; preds = %39
%47 = load i8*, i8** %6
%48 = call i64 @strcasecmp(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %46
store i32 -1, i32* %3
br label %63
51: ; preds = %46
br label %52
52: ; preds = %51, %43
br label %53
53: ; preds = %52, %36
br label %54
54: ; preds = %53, %29
br label %55
55: ; preds = %54, %22
br label %59
56: ; preds = %14
%57 = load double, double* %7
%58 = fdiv double %57, 8.000000e+00
store double %58, double* %7
br label %59
59: ; preds = %56, %55
%60 = load double, double* %7
%61 = fptoui double %60 to i32
%62 = load i32*, i32** %4
store i32 %61, i32* %62
store i32 0, i32* %3
br label %63
63: ; preds = %59, %50, %13
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [5 x i8] c"kbps\00"
@.str.1 = [5 x i8] c"mbps\00"
@.str.2 = [5 x i8] c"mbit\00"
@.str.3 = [5 x i8] c"kbit\00"
@.str.4 = [4 x i8] c"bps\00"
define i32 @get_rate(i32* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call double @strtod(i8* %1, i8** %3)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %1
br i1 %7, label %39, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %34, label %11
11: ; preds = %8
%12 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = fmul double %5, 1.024000e+03
br label %36
16: ; preds = %11
%17 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = fmul double %5, 0x4130000000000000
br label %36
21: ; preds = %16
%22 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = fmul double %5, 1.310720e+05
br label %36
26: ; preds = %21
%27 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = fmul double %5, 1.280000e+02
br label %36
31: ; preds = %26
%32 = tail call i64 @strcasecmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %39
34: ; preds = %8
%35 = fmul double %5, 1.250000e-01
br label %36
36: ; preds = %14, %24, %31, %29, %19, %34
%37 = phi double [ %15, %14 ], [ %20, %19 ], [ %25, %24 ], [ %30, %29 ], [ %5, %31 ], [ %35, %34 ]
%38 = fptoui double %37 to i32
store i32 %38, i32* %0
br label %39
39: ; preds = %31, %2, %36
%40 = phi i32 [ 0, %36 ], [ -1, %2 ], [ -1, %31 ]
ret i32 %40
}