#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 */
int chartoint(char const);
int pow_4(int);
int strlen(char const *);
int pattolong(const char *pat) {
  int i, result = 0, len;
  len = strlen(pat) - 1;
  for (i = 0; i <= len; i++)
    result += chartoint(pat[len - i]) * pow_4(i);
  return result;
}


x86 assembly (clang, -O0):
<pattolong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11a2 <pattolong+0x72>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <chartoint@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <pow_4@plt>
mov    %eax,%ecx
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 <pattolong+0x29>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pattolong>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    118c <pattolong+0x5c>
mov    %eax,%ebx
mov    %eax,%r13d
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebx,%rbx
movsbl (%r14,%rbx,1),%edi
call   1050 <chartoint@plt>
mov    %eax,%r12d
mov    %ebp,%edi
call   1040 <pow_4@plt>
imul   %r12d,%eax
add    %eax,%r15d
add    $0x1,%rbp
add    $0xffffffff,%ebx
cmp    %rbp,%r13
jne    1160 <pattolong+0x30>
jmp    118f <pattolong+0x5f>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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