#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 */
unsigned int get_pos_weight(int);
int /*<<< orphan*/ log_trace(char *);
scalar_t__ parse_number_from_single_char(char, int, int /*<<< orphan*/);
int /*<<< orphan*/ truncate_to(int, int);
unsigned int parse_number_from_char(char *c, int lsb, int msb) {
  if (0) {
    log_trace("ENTERING: parse_number_from_char");
  }
  unsigned int number = 0, char_count = 0;
  while (msb >= 0) {
    number += parse_number_from_single_char(c[char_count++], lsb,
                                            truncate_to(msb, 7));
    msb -= 8;
    lsb = 0;
    if (msb >= 7) {
      number *= get_pos_weight(8);
    }
  }
  if (0) {
    log_trace("LEAVING: parse_number_from_char");
  }
  return number;
}


x86 assembly (clang, -O0):
<parse_number_from_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11d0 <parse_number_from_char+0xa0>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
mov    $0x7,%esi
call   1030 <truncate_to@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
mov    -0x19(%rbp),%al
movsbl %al,%edi
call   1040 <parse_number_from_single_char@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x8,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x7,-0x10(%rbp)
jl     11cb <parse_number_from_char+0x9b>
mov    $0x8,%edi
call   1050 <get_pos_weight@plt>
imul   -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <parse_number_from_char+0x20>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number_from_char>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
js     117c <parse_number_from_char+0x4c>
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r14
movsbl (%rdi),%r15d
mov    %edx,%edi
mov    $0x7,%esi
call   1030 <truncate_to@plt>
mov    %r15d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <parse_number_from_single_char@plt>
mov    %rax,%r15
cmp    $0xf,%r12d
jb     1181 <parse_number_from_char+0x51>
mov    $0x8,%edi
call   1050 <get_pos_weight@plt>
imul   %r15d,%eax
mov    %eax,%r15d
jmp    1187 <parse_number_from_char+0x57>
xor    %r15d,%r15d
jmp    11f0 <parse_number_from_char+0xc0>
cmp    $0x8,%r12d
jb     11f0 <parse_number_from_char+0xc0>
add    $0x1,%r14
add    $0x8,%r12d
mov    %r15d,%ebx
jmp    11b1 <parse_number_from_char+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
add    $0xfffffff8,%r12d
mov    %r15d,%ebx
cmp    $0xf,%r12d
jbe    11f0 <parse_number_from_char+0xc0>
lea    -0x10(%r12),%ebp
movsbl (%r14),%r15d
mov    %ebp,%edi
mov    $0x7,%esi
call   1030 <truncate_to@plt>
mov    %r15d,%edi
xor    %esi,%esi
mov    %eax,%edx
call   1040 <parse_number_from_single_char@plt>
mov    %rax,%r15
add    %ebx,%r15d
cmp    $0xf,%ebp
jb     11a0 <parse_number_from_char+0x70>
mov    $0x8,%edi
call   1050 <get_pos_weight@plt>
imul   %r15d,%eax
mov    %eax,%r15d
jmp    11a0 <parse_number_from_char+0x70>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_number_from_char(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %35, %3
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %36
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = load i32, i32* %8
%15 = add i32 %14, 1
store i32 %15, i32* %8
%16 = zext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = load i8, i8* %17
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = call i32 @truncate_to(i32 %20, i32 7)
%22 = call i64 @parse_number_from_single_char(i8 signext %18, i32 %19, i32 %21)
%23 = load i32, i32* %7
%24 = zext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = sub nsw i32 %27, 8
store i32 %28, i32* %6
store i32 0, i32* %5
%29 = load i32, i32* %6
%30 = icmp sge i32 %29, 7
br i1 %30, label %31, label %35
31: ; preds = %12
%32 = call i32 @get_pos_weight(i32 8)
%33 = load i32, i32* %7
%34 = mul i32 %33, %32
store i32 %34, i32* %7
br label %35
35: ; preds = %31, %12
br label %9
36: ; preds = %9
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):
define i32 @parse_number_from_char(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, -1
br i1 %4, label %5, label %37
5: ; preds = %3
%6 = load i8, i8* %0
%7 = tail call i32 @truncate_to(i32 %2, i32 7)
%8 = tail call i64 @parse_number_from_single_char(i8 signext %6, i32 %1, i32 %7)
%9 = trunc i64 %8 to i32
%10 = icmp ugt i32 %2, 14
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = tail call i32 @get_pos_weight(i32 8)
%13 = mul i32 %12, %9
br label %16
14: ; preds = %5
%15 = icmp ugt i32 %2, 7
br i1 %15, label %16, label %37
16: ; preds = %11, %14
%17 = phi i32 [ %9, %14 ], [ %13, %11 ]
br label %18
18: ; preds = %16, %34
%19 = phi i64 [ %23, %34 ], [ 1, %16 ]
%20 = phi i32 [ %35, %34 ], [ %17, %16 ]
%21 = phi i32 [ %22, %34 ], [ %2, %16 ]
%22 = add nsw i32 %21, -8
%23 = add nuw nsw i64 %19, 1
%24 = getelementptr inbounds i8, i8* %0, i64 %19
%25 = load i8, i8* %24
%26 = tail call i32 @truncate_to(i32 %22, i32 7)
%27 = tail call i64 @parse_number_from_single_char(i8 signext %25, i32 0, i32 %26)
%28 = trunc i64 %27 to i32
%29 = add i32 %20, %28
%30 = icmp ugt i32 %22, 14
br i1 %30, label %31, label %34
31: ; preds = %18
%32 = tail call i32 @get_pos_weight(i32 8)
%33 = mul i32 %32, %29
br label %34
34: ; preds = %31, %18
%35 = phi i32 [ %33, %31 ], [ %29, %18 ]
%36 = icmp ugt i32 %21, 15
br i1 %36, label %18, label %37
37: ; preds = %34, %14, %3
%38 = phi i32 [ 0, %3 ], [ %9, %14 ], [ %35, %34 ]
ret i32 %38
}