unsigned long int parse_integer(s)
char *s;
{
  unsigned long int x;
  char *t;
  x = strtoul(s, &t, 0);
  if (s == t)
    hc_warn("unparseable integer string %s", s);
  switch (*t) {
  case '\0':
    break;
  case 'k':
  case 'K':
    x = x * (1024);
    t++;
    break;
  case 'm':
  case 'M':
    x = x * ((1024) * (1024));
    t++;
    break;
  case 'g':
  case 'G':
    x = x * (((1024) * (1024)) * (1024));
    t++;
    break;
  }
  if (*t != '\0')
    hc_warn("unrecognized characters in integer string %s", s);
  return x;
}


x86 assembly (clang, -O0):
<parse_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    115f <parse_integer+0x3f>
mov    -0x8(%rbp),%rsi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <hc_warn@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11dc <parse_integer+0xbc>
jmp    1176 <parse_integer+0x56>
mov    -0x1c(%rbp),%eax
sub    $0x47,%eax
je     121b <parse_integer+0xfb>
jmp    1187 <parse_integer+0x67>
mov    -0x1c(%rbp),%eax
sub    $0x4b,%eax
je     11e1 <parse_integer+0xc1>
jmp    1198 <parse_integer+0x78>
mov    -0x1c(%rbp),%eax
sub    $0x4d,%eax
je     11fe <parse_integer+0xde>
jmp    11a9 <parse_integer+0x89>
mov    -0x1c(%rbp),%eax
sub    $0x67,%eax
je     121b <parse_integer+0xfb>
jmp    11ba <parse_integer+0x9a>
mov    -0x1c(%rbp),%eax
sub    $0x6b,%eax
je     11e1 <parse_integer+0xc1>
jmp    11cb <parse_integer+0xab>
mov    -0x1c(%rbp),%eax
sub    $0x6d,%eax
je     11fe <parse_integer+0xde>
jmp    1233 <parse_integer+0x113>
jmp    1233 <parse_integer+0x113>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1233 <parse_integer+0x113>
mov    -0x10(%rbp),%rax
shl    $0x14,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1233 <parse_integer+0x113>
mov    -0x10(%rbp),%rax
shl    $0x1e,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1255 <parse_integer+0x135>
mov    -0x8(%rbp),%rsi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <hc_warn@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_integer>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rbx
cmp    %r15,%rbx
jne    1156 <parse_integer+0x36>
lea    0xeb4(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <hc_warn@plt>
movsbl (%rbx),%eax
mov    %eax,%edx
add    $0xffffffb9,%edx
cmp    $0x26,%edx
ja     11aa <parse_integer+0x8a>
movabs $0x100000001,%rcx
bt     %rdx,%rcx
jb     119f <parse_integer+0x7f>
mov    $0xa,%ecx
movabs $0x1000000010,%rsi
bt     %rdx,%rsi
jb     11a4 <parse_integer+0x84>
movabs $0x4000000040,%rcx
bt     %rdx,%rcx
jae    11aa <parse_integer+0x8a>
mov    $0x14,%ecx
jmp    11a4 <parse_integer+0x84>
mov    $0x1e,%ecx
shl    %cl,%r14
mov    0x1(%rbx),%al
test   %al,%al
je     11bf <parse_integer+0x9f>
lea    0xe69(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <hc_warn@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"unparseable integer string %s\00"
@.str.1 = [45 x i8] c"unrecognized characters in integer string %s\00"
define i64 @parse_integer(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtoul(i8* %5, i8** %4, i32 0)
store i64 %6, i64* %3
%7 = load i8*, i8** %2
%8 = load i8*, i8** %4
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @hc_warn to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %1
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %33 [
i32 0, label %17
i32 107, label %18
i32 75, label %18
i32 109, label %23
i32 77, label %23
i32 103, label %28
i32 71, label %28
]
17: ; preds = %13
br label %33
18: ; preds = %13, %13
%19 = load i64, i64* %3
%20 = mul i64 %19, 1024
store i64 %20, i64* %3
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
br label %33
23: ; preds = %13, %13
%24 = load i64, i64* %3
%25 = mul i64 %24, 1048576
store i64 %25, i64* %3
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
br label %33
28: ; preds = %13, %13
%29 = load i64, i64* %3
%30 = mul i64 %29, 1073741824
store i64 %30, i64* %3
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
br label %33
33: ; preds = %13, %28, %23, %18, %17
%34 = load i8*, i8** %4
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i8*, i8** %2
%40 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @hc_warn to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %33
%42 = load i64, i64* %3
ret i64 %42
}

LLVM IR (-O2):
@.str = [30 x i8] c"unparseable integer string %s\00"
@.str.1 = [45 x i8] c"unrecognized characters in integer string %s\00"
define i64 @parse_integer(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 0)
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, %0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @hc_warn to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %1
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
switch i32 %11, label %19 [
i32 71, label %13
i32 107, label %14
i32 75, label %14
i32 109, label %12
i32 77, label %12
i32 103, label %13
]
12: ; preds = %9, %9
br label %14
13: ; preds = %9, %9
br label %14
14: ; preds = %9, %9, %12, %13
%15 = phi i64 [ 20, %12 ], [ 30, %13 ], [ 10, %9 ], [ 10, %9 ]
%16 = shl i64 %4, %15
%17 = getelementptr inbounds i8, i8* %5, i64 1
%18 = load i8, i8* %17
br label %19
19: ; preds = %14, %9
%20 = phi i8 [ %18, %14 ], [ %10, %9 ]
%21 = phi i64 [ %16, %14 ], [ %4, %9 ]
%22 = icmp eq i8 %20, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @hc_warn to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %25
25: ; preds = %23, %19
ret i64 %21
}