#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 toint(char);
int agency_code(char fascn[40]) {
  int temp;
  temp = toint(fascn[1]) * 1000;
  temp += toint(fascn[2]) * 100;
  temp += toint(fascn[3]) * 10;
  temp += toint(fascn[4]);
  return (temp);
}


x86 assembly (clang, -O0):
<agency_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toint@plt>
imul   $0x3e8,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <toint@plt>
imul   $0x64,%eax,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <toint@plt>
imul   $0xa,%eax,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x4(%rax),%edi
call   1030 <toint@plt>
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<agency_code>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
movsbl 0x1(%rdi),%edi
call   1030 <toint@plt>
imul   $0x3e8,%eax,%r14d
movsbl 0x2(%rbx),%edi
call   1030 <toint@plt>
imul   $0x64,%eax,%ebp
add    %r14d,%ebp
movsbl 0x3(%rbx),%edi
call   1030 <toint@plt>
lea    (%rax,%rax,4),%eax
lea    0x0(%rbp,%rax,2),%ebp
movsbl 0x4(%rbx),%edi
call   1030 <toint@plt>
add    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @agency_code(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = load i8, i8* %5
%7 = call i32 @toint(i8 signext %6)
%8 = mul nsw i32 %7, 1000
store i32 %8, i32* %3
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 2
%11 = load i8, i8* %10
%12 = call i32 @toint(i8 signext %11)
%13 = mul nsw i32 %12, 100
%14 = load i32, i32* %3
%15 = add nsw i32 %14, %13
store i32 %15, i32* %3
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 3
%18 = load i8, i8* %17
%19 = call i32 @toint(i8 signext %18)
%20 = mul nsw i32 %19, 10
%21 = load i32, i32* %3
%22 = add nsw i32 %21, %20
store i32 %22, i32* %3
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = load i8, i8* %24
%26 = call i32 @toint(i8 signext %25)
%27 = load i32, i32* %3
%28 = add nsw i32 %27, %26
store i32 %28, i32* %3
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @agency_code(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = tail call i32 @toint(i8 signext %3)
%5 = mul nsw i32 %4, 1000
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = tail call i32 @toint(i8 signext %7)
%9 = mul nsw i32 %8, 100
%10 = add nsw i32 %9, %5
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = load i8, i8* %11
%13 = tail call i32 @toint(i8 signext %12)
%14 = mul nsw i32 %13, 10
%15 = add nsw i32 %10, %14
%16 = getelementptr inbounds i8, i8* %0, i64 4
%17 = load i8, i8* %16
%18 = tail call i32 @toint(i8 signext %17)
%19 = add nsw i32 %15, %18
ret i32 %19
}