#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 get_mult_bytes(char, void *);
int sscanf(char const *, char *, long *, ...);
int /*<<< orphan*/ strlen(char const *);
int check_range_bytes(const char *str, long *val, void *data) {
  char suffix;
  if (!strlen(str))
    return 1;
  if (sscanf(str, "%lu%c", val, &suffix) == 2) {
    *val *= get_mult_bytes(suffix, data);
    return 0;
  }
  if (sscanf(str, "%lu", val) == 1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<check_range_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1162 <check_range_bytes+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11e0 <check_range_bytes+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe8f(%rip),%rsi
lea    -0x21(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    11ae <check_range_bytes+0x7e>
mov    -0x21(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1040 <get_mult_bytes@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
imul   (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11e0 <check_range_bytes+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11d9 <check_range_bytes+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <check_range_bytes+0xb0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_range_bytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     117f <check_range_bytes+0x4f>
lea    0xeb0(%rip),%rsi
xor    %ebp,%ebp
lea    0x7(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    1186 <check_range_bytes+0x56>
movsbl 0x7(%rsp),%edi
mov    %r14,%rsi
call   1040 <get_mult_bytes@plt>
imul   (%r15),%rax
mov    %rax,(%r15)
jmp    11a3 <check_range_bytes+0x73>
mov    $0x1,%ebp
jmp    11a3 <check_range_bytes+0x73>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%lu%c\00"
@.str.1 = [4 x i8] c"%lu\00"
define i32 @check_range_bytes(i8* %0, i64* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i8*
%8 = alloca i8
store i8* %0, i8** %5
store i64* %1, i64** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 1, i32* %4
br label %32
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i64*, i64** %6
%16 = call i32 (i8*, i8*, i64*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %15, i8* %8)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = load i8, i8* %8
%20 = load i8*, i8** %7
%21 = call i64 @get_mult_bytes(i8 signext %19, i8* %20)
%22 = load i64*, i64** %6
%23 = load i64, i64* %22
%24 = mul nsw i64 %23, %21
store i64 %24, i64* %22
store i32 0, i32* %4
br label %32
25: ; preds = %13
%26 = load i8*, i8** %5
%27 = load i64*, i64** %6
%28 = call i32 (i8*, i8*, i64*, ...) @sscanf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %27)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 0, i32* %4
br label %32
31: ; preds = %25
store i32 1, i32* %4
br label %32
32: ; preds = %31, %30, %18, %12
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [6 x i8] c"%lu%c\00"
@.str.1 = [4 x i8] c"%lu\00"
define i32 @check_range_bytes(i8* %0, i64* %1, i8* %2) {
%4 = alloca i8
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %3
%8 = call i32 (i8*, i8*, i64*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64* %1, i8* %4)
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i8, i8* %4
%12 = call i64 @get_mult_bytes(i8 signext %11, i8* %2)
%13 = load i64, i64* %1
%14 = mul nsw i64 %13, %12
store i64 %14, i64* %1
br label %19
15: ; preds = %7
%16 = call i32 (i8*, i8*, i64*, ...) @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%17 = icmp ne i32 %16, 1
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %15, %3, %10
%20 = phi i32 [ 0, %10 ], [ 1, %3 ], [ %18, %15 ]
ret i32 %20
}