#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*/ print_error(char *, char const);
long strtol(char const *, char **, int);
long parse_number_unit(const char *val) {
  char *endptr;
  long n = strtol(val, &endptr, 10);
  if ((endptr != NULL) && (*endptr != '\0')) {
    const char unit = *endptr;
    switch (unit) {
    case 'k':
    case 'K':
      n *= 1024L;
      break;
    case 'm':
    case 'M':
      n *= 1024L * 1024L;
      break;
    case 'g':
    case 'G':
      n *= 1024L * 1024L * 1024L;
      break;
    default:
      print_error("num-images has invalid unit (%c), use K, M, G", unit);
      break;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<parse_number_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1218 <parse_number_unit+0xf8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1218 <parse_number_unit+0xf8>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x47,%eax
je     11f2 <parse_number_unit+0xd2>
jmp    117b <parse_number_unit+0x5b>
mov    -0x20(%rbp),%eax
sub    $0x4b,%eax
je     11d0 <parse_number_unit+0xb0>
jmp    118c <parse_number_unit+0x6c>
mov    -0x20(%rbp),%eax
sub    $0x4d,%eax
je     11e1 <parse_number_unit+0xc1>
jmp    119d <parse_number_unit+0x7d>
mov    -0x20(%rbp),%eax
sub    $0x67,%eax
je     11f2 <parse_number_unit+0xd2>
jmp    11ae <parse_number_unit+0x8e>
mov    -0x20(%rbp),%eax
sub    $0x6b,%eax
je     11d0 <parse_number_unit+0xb0>
jmp    11bf <parse_number_unit+0x9f>
mov    -0x20(%rbp),%eax
sub    $0x6d,%eax
je     11e1 <parse_number_unit+0xc1>
jmp    1203 <parse_number_unit+0xe3>
mov    -0x18(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x18(%rbp)
jmp    1213 <parse_number_unit+0xf3>
mov    -0x18(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x18(%rbp)
jmp    1213 <parse_number_unit+0xf3>
mov    -0x18(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x18(%rbp)
jmp    1213 <parse_number_unit+0xf3>
lea    0xdf6(%rip),%rdi
movsbl -0x19(%rbp),%esi
call   1030 <print_error@plt>
jmp    1218 <parse_number_unit+0xf8>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number_unit>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
test   %rax,%rax
je     119e <parse_number_unit+0x7e>
movsbl (%rax),%esi
test   %esi,%esi
je     119e <parse_number_unit+0x7e>
lea    -0x47(%rsi),%eax
cmp    $0x26,%eax
ja     1192 <parse_number_unit+0x72>
movabs $0x100000001,%rcx
bt     %rax,%rcx
jb     118c <parse_number_unit+0x6c>
movabs $0x1000000010,%rcx
bt     %rax,%rcx
jb     1186 <parse_number_unit+0x66>
movabs $0x4000000040,%rcx
bt     %rax,%rcx
jae    1192 <parse_number_unit+0x72>
shl    $0x14,%rbx
jmp    119e <parse_number_unit+0x7e>
shl    $0xa,%rbx
jmp    119e <parse_number_unit+0x7e>
shl    $0x1e,%rbx
jmp    119e <parse_number_unit+0x7e>
lea    0xe67(%rip),%rdi
call   1030 <print_error@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"num-images has invalid unit (%c), use K, M, G\00"
define i64 @parse_number_unit(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strtol(i8* %6, i8** %3, i32 10)
store i64 %7, i64* %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %33
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
switch i32 %19, label %29 [
i32 107, label %20
i32 75, label %20
i32 109, label %23
i32 77, label %23
i32 103, label %26
i32 71, label %26
]
20: ; preds = %15, %15
%21 = load i64, i64* %4
%22 = mul nsw i64 %21, 1024
store i64 %22, i64* %4
br label %32
23: ; preds = %15, %15
%24 = load i64, i64* %4
%25 = mul nsw i64 %24, 1048576
store i64 %25, i64* %4
br label %32
26: ; preds = %15, %15
%27 = load i64, i64* %4
%28 = mul nsw i64 %27, 1073741824
store i64 %28, i64* %4
br label %32
29: ; preds = %15
%30 = load i8, i8* %5
%31 = call i32 @print_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8 signext %30)
br label %32
32: ; preds = %29, %26, %23, %20
br label %33
33: ; preds = %32, %10, %1
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
@.str = [46 x i8] c"num-images has invalid unit (%c), use K, M, G\00"
define i64 @parse_number_unit(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %1
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = sext i8 %8 to i32
switch i32 %11, label %18 [
i32 107, label %12
i32 75, label %12
i32 109, label %14
i32 77, label %14
i32 103, label %16
i32 71, label %16
]
12: ; preds = %10, %10
%13 = shl nsw i64 %4, 10
br label %20
14: ; preds = %10, %10
%15 = shl nsw i64 %4, 20
br label %20
16: ; preds = %10, %10
%17 = shl nsw i64 %4, 30
br label %20
18: ; preds = %10
%19 = tail call i32 @print_error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8 signext %8)
br label %20
20: ; preds = %12, %14, %16, %18, %7, %1
%21 = phi i64 [ %4, %7 ], [ %4, %1 ], [ %4, %18 ], [ %17, %16 ], [ %15, %14 ], [ %13, %12 ]
ret i64 %21
}