#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*/ errx(int, char *, char const *, ...);
scalar_t__ strcmp(char *, char *);
long strtol(char const *, char **, int /*<<< orphan*/);
long getValue(const char *desc, const char *val, long min, long max) {
  long result;
  char *endp;
  result = strtol(val, &endp, 0);
  if (*endp != '\0') {
    if (strcmp(endp, "b") == 0) {
      result *= 512;
    } else if (strcmp(endp, "k") == 0) {
      result *= 1024;
    } else if (strcmp(endp, "m") == 0) {
      result *= 1048576;
    } else if (strcmp(endp, "w") == 0) {
      result *= sizeof(int);
    } else {
      errx(1, "%s, unknown suffix '%s'", desc, endp);
    }
  }
  if (result < min || result > max) {
    errx(1, "%s, value out of range", desc);
  }
  return result;
}


x86 assembly (clang, -O0):
<getValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1246 <getValue+0x116>
mov    -0x30(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1196 <getValue+0x66>
mov    -0x28(%rbp),%rax
shl    $0x9,%rax
mov    %rax,-0x28(%rbp)
jmp    1241 <getValue+0x111>
mov    -0x30(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c1 <getValue+0x91>
mov    -0x28(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x28(%rbp)
jmp    123c <getValue+0x10c>
mov    -0x30(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <getValue+0xbc>
mov    -0x28(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x28(%rbp)
jmp    1237 <getValue+0x107>
mov    -0x30(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1217 <getValue+0xe7>
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
mov    %rax,-0x28(%rbp)
jmp    1232 <getValue+0x102>
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
jmp    1237 <getValue+0x107>
jmp    123c <getValue+0x10c>
jmp    1241 <getValue+0x111>
jmp    1246 <getValue+0x116>
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     1262 <getValue+0x132>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    1279 <getValue+0x149>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getValue>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rax
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rbx
cmpb   $0x0,(%rbx)
je     11f3 <getValue+0xc3>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d9 <getValue+0xa9>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e4 <getValue+0xb4>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ef <getValue+0xbf>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1224 <getValue+0xf4>
lea    0xe48(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <errx@plt>
cmp    %r12,%r13
jge    11f8 <getValue+0xc8>
jmp    11fd <getValue+0xcd>
shl    $0x9,%r13
cmp    %r12,%r13
jge    11f8 <getValue+0xc8>
jmp    11fd <getValue+0xcd>
shl    $0xa,%r13
cmp    %r12,%r13
jge    11f8 <getValue+0xc8>
jmp    11fd <getValue+0xcd>
shl    $0x14,%r13
cmp    %r12,%r13
jl     11fd <getValue+0xcd>
cmp    %r15,%r13
jle    1213 <getValue+0xe3>
lea    0xe1c(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <errx@plt>
mov    %r13,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
shl    $0x2,%r13
cmp    %r12,%r13
jge    11f8 <getValue+0xc8>
jmp    11fd <getValue+0xcd>

LLVM IR (-O0):
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"k\00"
@.str.2 = [2 x i8] c"m\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [24 x i8] c"%s, unknown suffix '%s'\00"
@.str.5 = [23 x i8] c"%s, value out of range\00"
define i64 @getValue(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i8*, i8** %6
%12 = call i64 @strtol(i8* %11, i8** %10, i32 0)
store i64 %12, i64* %9
%13 = load i8*, i8** %10
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %53
17: ; preds = %4
%18 = load i8*, i8** %10
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i64, i64* %9
%23 = mul nsw i64 %22, 512
store i64 %23, i64* %9
br label %52
24: ; preds = %17
%25 = load i8*, i8** %10
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i64, i64* %9
%30 = mul nsw i64 %29, 1024
store i64 %30, i64* %9
br label %51
31: ; preds = %24
%32 = load i8*, i8** %10
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i64, i64* %9
%37 = mul nsw i64 %36, 1048576
store i64 %37, i64* %9
br label %50
38: ; preds = %31
%39 = load i8*, i8** %10
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = load i64, i64* %9
%44 = mul i64 %43, 4
store i64 %44, i64* %9
br label %49
45: ; preds = %38
%46 = load i8*, i8** %5
%47 = load i8*, i8** %10
%48 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %45, %42
br label %50
50: ; preds = %49, %35
br label %51
51: ; preds = %50, %28
br label %52
52: ; preds = %51, %21
br label %53
53: ; preds = %52, %4
%54 = load i64, i64* %9
%55 = load i64, i64* %7
%56 = icmp slt i64 %54, %55
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i64, i64* %9
%59 = load i64, i64* %8
%60 = icmp sgt i64 %58, %59
br i1 %60, label %61, label %64
61: ; preds = %57, %53
%62 = load i8*, i8** %5
%63 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %57
%65 = load i64, i64* %9
ret i64 %65
}

LLVM IR (-O2):
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"k\00"
@.str.2 = [2 x i8] c"m\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [24 x i8] c"%s, unknown suffix '%s'\00"
@.str.5 = [23 x i8] c"%s, value out of range\00"
define i64 @getValue(i8* %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = call i64 @strtol(i8* %1, i8** %5, i32 0)
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %33, label %11
11: ; preds = %4
%12 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = shl nsw i64 %7, 9
br label %33
16: ; preds = %11
%17 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 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 = shl nsw i64 %7, 10
br label %33
21: ; preds = %16
%22 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 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 = shl nsw i64 %7, 20
br label %33
26: ; preds = %21
%27 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 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 = shl i64 %7, 2
br label %33
31: ; preds = %26
%32 = tail call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %8)
br label %33
33: ; preds = %14, %24, %31, %29, %19, %4
%34 = phi i64 [ %15, %14 ], [ %20, %19 ], [ %25, %24 ], [ %30, %29 ], [ %7, %31 ], [ %7, %4 ]
%35 = icmp slt i64 %34, %2
%36 = icmp sgt i64 %34, %3
%37 = or i1 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = tail call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %40
40: ; preds = %33, %38
ret i64 %34
}