#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 */
long strtol(char const *, char **, int);
int get_length_arg(const char *arg, unsigned long *value) {
  long t;
  char *suffix;
  t = strtol(arg, &suffix, 10);
  if (*suffix == 'b') {
    suffix++;
  } else if (*suffix == 'k') {
    t *= 1024;
    suffix++;
  }
  if (t < 0 || *suffix != 0) {
    return 1;
  }
  *value = (unsigned long)t;
  return 0;
}


x86 assembly (clang, -O0):
<get_length_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x62,%eax
jne    1157 <get_length_arg+0x47>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1184 <get_length_arg+0x74>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6b,%eax
jne    117f <get_length_arg+0x6f>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1184 <get_length_arg+0x74>
cmpq   $0x0,-0x20(%rbp)
jl     119f <get_length_arg+0x8f>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ab <get_length_arg+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    11bd <get_length_arg+0xad>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_length_arg>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rdx
mov    (%rdx),%cl
cmp    $0x6b,%cl
je     113a <get_length_arg+0x2a>
cmp    $0x62,%cl
je     113e <get_length_arg+0x2e>
jmp    1142 <get_length_arg+0x32>
shl    $0xa,%rax
add    $0x1,%rdx
mov    $0x1,%ecx
test   %rax,%rax
js     1156 <get_length_arg+0x46>
cmpb   $0x0,(%rdx)
jne    1156 <get_length_arg+0x46>
mov    %rax,(%rbx)
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @get_length_arg(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %7, i32 10)
store i64 %9, i64* %6
%10 = load i8*, i8** %7
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 98
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %7
br label %28
17: ; preds = %2
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 107
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i64, i64* %6
%24 = mul nsw i64 %23, 1024
store i64 %24, i64* %6
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
br label %27
27: ; preds = %22, %17
br label %28
28: ; preds = %27, %14
%29 = load i64, i64* %6
%30 = icmp slt i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = load i8*, i8** %7
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31, %28
store i32 1, i32* %3
br label %40
37: ; preds = %31
%38 = load i64, i64* %6
%39 = load i64*, i64** %5
store i64 %38, i64* %39
store i32 0, i32* %3
br label %40
40: ; preds = %37, %36
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @get_length_arg(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
switch i8 %7, label %13 [
i8 98, label %8
i8 107, label %10
]
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %6, i64 1
br label %13
10: ; preds = %2
%11 = shl nsw i64 %5, 10
%12 = getelementptr inbounds i8, i8* %6, i64 1
br label %13
13: ; preds = %2, %10, %8
%14 = phi i8* [ %9, %8 ], [ %12, %10 ], [ %6, %2 ]
%15 = phi i64 [ %5, %8 ], [ %11, %10 ], [ %5, %2 ]
%16 = icmp slt i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8, i8* %14
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i64 %15, i64* %1
br label %21
21: ; preds = %13, %17, %20
%22 = phi i32 [ 0, %20 ], [ 1, %17 ], [ 1, %13 ]
ret i32 %22
}