#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 */
scalar_t__ chartoint(unsigned char);
int mnpow(int, int);
int slen(unsigned char *);
unsigned char bytestoint(unsigned char *bytes) {
  int i = 0;
  int ret = 0;
  int len = slen(bytes) - 1;
  while (bytes[i] != 0x00) {
    ret += (mnpow(10, len - i) * (int)chartoint(bytes[i]));
    i++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<bytestoint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <slen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11af <bytestoint+0x7f>
mov    -0x14(%rbp),%esi
sub    -0xc(%rbp),%esi
mov    $0xa,%edi
call   1050 <mnpow@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <chartoint@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1159 <bytestoint+0x29>
mov    -0x10(%rbp),%eax
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytestoint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <slen@plt>
xor    %r14d,%r14d
cmpb   $0x0,(%rbx)
je     117b <bytestoint+0x4b>
mov    %eax,%ebp
add    $0xffffffff,%ebp
add    $0x1,%rbx
mov    $0xa,%edi
mov    %ebp,%esi
call   1050 <mnpow@plt>
mov    %eax,%r15d
movzbl -0x1(%rbx),%edi
call   1040 <chartoint@plt>
imul   %r15d,%eax
add    %eax,%r14d
add    $0xffffffff,%ebp
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <bytestoint+0x20>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define zeroext i8 @bytestoint(i8* %0) {
%2 = tail call i32 @slen(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %18, %5 ], [ 0, %1 ]
%7 = phi i8* [ %19, %5 ], [ %0, %1 ]
%8 = phi i32 [ %17, %5 ], [ 0, %1 ]
%9 = trunc i64 %6 to i32
%10 = xor i32 %9, -1
%11 = add i32 %2, %10
%12 = tail call i32 @mnpow(i32 10, i32 %11)
%13 = load i8, i8* %7
%14 = tail call i64 @chartoint(i8 zeroext %13)
%15 = trunc i64 %14 to i32
%16 = mul nsw i32 %12, %15
%17 = add nsw i32 %16, %8
%18 = add nuw i64 %6, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %5
%23 = trunc i32 %17 to i8
br label %24
24: ; preds = %22, %1
%25 = phi i8 [ 0, %1 ], [ %23, %22 ]
ret i8 %25
}