#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 */
typedef int /*<<< orphan*/ uint32_t;
struct BigNum {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bnAddQ(struct BigNum *, int /*<<< orphan*/);
int /*<<< orphan*/ bnMulQ(struct BigNum *, struct BigNum *, int);
int /*<<< orphan*/ bnSetQ(struct BigNum *, int /*<<< orphan*/);
int /*<<< orphan*/ getAsciiDigit(int /*<<< orphan*/ *, int, char);
int strlen(char *);
int bnReadAscii(struct BigNum *X, char *s, int radix) {
  int slen = strlen(s);
  int i, neg = 0;
  uint32_t d;
  bnSetQ(X, 0);
  for (i = 0; i < slen; i++) {
    if (i == 0 && s[i] == '-') {
      neg = 1;
      continue;
    }
    getAsciiDigit(&d, radix, s[i]);
    bnMulQ(X, X, radix);
    bnAddQ(X, d);
  }
  return (neg);
}


x86 assembly (clang, -O0):
<bnReadAscii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1070 <bnSetQ@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1201 <bnReadAscii+0xb1>
cmpl   $0x0,-0x1c(%rbp)
jne    11bf <bnReadAscii+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    11bf <bnReadAscii+0x6f>
movl   $0x1,-0x20(%rbp)
jmp    11f3 <bnReadAscii+0xa3>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    -0x24(%rbp),%rdi
movsbl (%rax,%rcx,1),%edx
call   1050 <getAsciiDigit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <bnMulQ@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <bnAddQ@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <bnReadAscii+0x38>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bnReadAscii>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <bnSetQ@plt>
test   %r12d,%r12d
jle    1205 <bnReadAscii+0xb5>
mov    (%r14),%al
mov    $0x1,%r15d
cmp    $0x2d,%al
je     11b9 <bnReadAscii+0x69>
movsbl %al,%edx
mov    %rsp,%rdi
mov    %ebp,%esi
call   1050 <getAsciiDigit@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <bnMulQ@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1060 <bnAddQ@plt>
xor    %r15d,%r15d
cmp    $0x1,%r12d
je     1205 <bnReadAscii+0xb5>
mov    %r15d,0x4(%rsp)
mov    %r12d,%r13d
mov    $0x1,%r15d
mov    %rsp,%r12
movsbl (%r14,%r15,1),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <getAsciiDigit@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <bnMulQ@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1060 <bnAddQ@plt>
add    $0x1,%r15
cmp    %r15,%r13
jne    11d0 <bnReadAscii+0x80>
mov    0x4(%rsp),%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.BigNum = type { i32 }
define i32 @bnReadAscii(%struct.BigNum* %0, i8* %1, i32 %2) {
%4 = alloca %struct.BigNum*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.BigNum* %0, %struct.BigNum** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
store i32 0, i32* %9
%13 = load %struct.BigNum*, %struct.BigNum** %4
%14 = call i32 @bnSetQ(%struct.BigNum* %13, i32 0)
store i32 0, i32* %8
br label %15
15: ; preds = %46, %3
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %49
19: ; preds = %15
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i8*, i8** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 45
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 1, i32* %9
br label %46
31: ; preds = %22, %19
%32 = load i32, i32* %6
%33 = load i8*, i8** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i32 @getAsciiDigit(i32* %10, i32 %32, i8 signext %37)
%39 = load %struct.BigNum*, %struct.BigNum** %4
%40 = load %struct.BigNum*, %struct.BigNum** %4
%41 = load i32, i32* %6
%42 = call i32 @bnMulQ(%struct.BigNum* %39, %struct.BigNum* %40, i32 %41)
%43 = load %struct.BigNum*, %struct.BigNum** %4
%44 = load i32, i32* %10
%45 = call i32 @bnAddQ(%struct.BigNum* %43, i32 %44)
br label %46
46: ; preds = %31, %30
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %15
49: ; preds = %15
%50 = load i32, i32* %9
ret i32 %50
}

LLVM IR (-O2):
%struct.BigNum = type { i32 }
define i32 @bnReadAscii(%struct.BigNum* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = tail call i32 @strlen(i8* %1)
%6 = bitcast i32* %4 to i8*
%7 = tail call i32 @bnSetQ(%struct.BigNum* %0, i32 0)
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %31
9: ; preds = %3
%10 = zext i32 %5 to i64
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 45
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = call i32 @getAsciiDigit(i32* %4, i32 %2, i8 signext %11)
%15 = call i32 @bnMulQ(%struct.BigNum* %0, %struct.BigNum* %0, i32 %2)
%16 = load i32, i32* %4
%17 = call i32 @bnAddQ(%struct.BigNum* %0, i32 %16)
br label %18
18: ; preds = %13, %9
%19 = phi i32 [ 0, %13 ], [ 1, %9 ]
%20 = icmp eq i32 %5, 1
br i1 %20, label %31, label %21
21: ; preds = %18, %21
%22 = phi i64 [ %29, %21 ], [ 1, %18 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @getAsciiDigit(i32* %4, i32 %2, i8 signext %24)
%26 = call i32 @bnMulQ(%struct.BigNum* %0, %struct.BigNum* %0, i32 %2)
%27 = load i32, i32* %4
%28 = call i32 @bnAddQ(%struct.BigNum* %0, i32 %27)
%29 = add nuw nsw i64 %22, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %21
31: ; preds = %21, %18, %3
%32 = phi i32 [ 0, %3 ], [ %19, %18 ], [ %19, %21 ]
ret i32 %32
}