#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*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned long);
int /*<<< orphan*/ mpz_mul_ui(int /*<<< orphan*/, int /*<<< orphan*/,
                              unsigned long);
int /*<<< orphan*/ mpz_neg(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set_ui(int /*<<< orphan*/, unsigned long);
int mpz_EGlpNumReadStr(mpz_t var, char const *str) {
  char unsigned a_sgn = 1;
  char unsigned sgn = 0;
  char c = 0;
  int n_char = 0;
  c = str[n_char];
  mpz_set_ui(var, (unsigned long int)0);
  while ((('0' <= c) && (c <= '9')) || (a_sgn && (c == '+' || c == '-'))) {
    switch (c) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      mpz_mul_ui(var, var, (unsigned long int)10);
      mpz_add_ui(var, var, (unsigned long int)(c - '0'));
      a_sgn = 0;
      break;
    case '-':
      sgn = 1;
    case '+':
      a_sgn = 0;
      break;
    }
    c = str[++n_char];
  }
  if (sgn)
    mpz_neg(var, var);
  return n_char;
}


x86 assembly (clang, -O0):
<mpz_EGlpNumReadStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x1,-0x11(%rbp)
movb   $0x0,-0x12(%rbp)
movb   $0x0,-0x13(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <mpz_set_ui@plt>
movsbl -0x13(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     119f <mpz_EGlpNumReadStr+0x5f>
movsbl -0x13(%rbp),%ecx
mov    $0x1,%al
cmp    $0x39,%ecx
mov    %al,-0x19(%rbp)
jle    11dc <mpz_EGlpNumReadStr+0x9c>
movzbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
je     11d6 <mpz_EGlpNumReadStr+0x96>
movsbl -0x13(%rbp),%ecx
mov    $0x1,%al
cmp    $0x2b,%ecx
mov    %al,-0x1b(%rbp)
je     11d0 <mpz_EGlpNumReadStr+0x90>
movsbl -0x13(%rbp),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ec <mpz_EGlpNumReadStr+0xac>
jmp    1277 <mpz_EGlpNumReadStr+0x137>
movsbl -0x13(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x2b,%eax
je     1258 <mpz_EGlpNumReadStr+0x118>
jmp    1201 <mpz_EGlpNumReadStr+0xc1>
mov    -0x20(%rbp),%eax
sub    $0x2d,%eax
je     1254 <mpz_EGlpNumReadStr+0x114>
jmp    1212 <mpz_EGlpNumReadStr+0xd2>
mov    -0x20(%rbp),%eax
add    $0xffffffd0,%eax
sub    $0x9,%eax
ja     125c <mpz_EGlpNumReadStr+0x11c>
jmp    1226 <mpz_EGlpNumReadStr+0xe6>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0xa,%edx
call   1060 <mpz_mul_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
movsbl -0x13(%rbp),%eax
sub    $0x30,%eax
movslq %eax,%rdx
call   1030 <mpz_add_ui@plt>
movb   $0x0,-0x11(%rbp)
jmp    125c <mpz_EGlpNumReadStr+0x11c>
movb   $0x1,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
jmp    117c <mpz_EGlpNumReadStr+0x3c>
cmpb   $0x0,-0x12(%rbp)
je     128c <mpz_EGlpNumReadStr+0x14c>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <mpz_neg@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpz_EGlpNumReadStr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    (%rsi),%bl
xor    %r15d,%r15d
xor    %esi,%esi
call   1050 <mpz_set_ui@plt>
mov    $0x1,%al
xor    %r12d,%r12d
jmp    1191 <mpz_EGlpNumReadStr+0x51>
movsbl %bl,%ecx
lea    -0x30(%rcx),%ebx
cmp    $0xa,%ebx
jae    11b0 <mpz_EGlpNumReadStr+0x70>
mov    $0xa,%edx
mov    %ebp,%edi
mov    %ebp,%esi
call   1060 <mpz_mul_ui@plt>
mov    %ebp,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
call   1030 <mpz_add_ui@plt>
xor    %eax,%eax
movzbl 0x1(%r14,%r15,1),%ebx
add    $0x1,%r15
lea    -0x30(%rbx),%ecx
cmp    $0xa,%cl
jb     1160 <mpz_EGlpNumReadStr+0x20>
test   %al,%al
je     11bf <mpz_EGlpNumReadStr+0x7f>
cmp    $0x2d,%bl
je     1160 <mpz_EGlpNumReadStr+0x20>
cmp    $0x2b,%bl
je     1160 <mpz_EGlpNumReadStr+0x20>
jmp    11bf <mpz_EGlpNumReadStr+0x7f>
nopl   0x0(%rax)
cmp    $0x2b,%ecx
je     1185 <mpz_EGlpNumReadStr+0x45>
cmp    $0x2d,%ecx
jne    1187 <mpz_EGlpNumReadStr+0x47>
mov    $0x1,%r12b
jmp    1185 <mpz_EGlpNumReadStr+0x45>
test   %r12b,%r12b
je     11cd <mpz_EGlpNumReadStr+0x8d>
mov    %ebp,%edi
mov    %ebp,%esi
call   1040 <mpz_neg@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mpz_EGlpNumReadStr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8 1, i8* %5
store i8 0, i8* %6
store i8 0, i8* %7
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = load i32, i32* %8
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
store i8 %13, i8* %7
%14 = load i32, i32* %3
%15 = call i32 @mpz_set_ui(i32 %14, i64 0)
br label %16
16: ; preds = %58, %2
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
%19 = icmp sle i32 48, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 57
br i1 %23, label %40, label %24
24: ; preds = %20, %16
%25 = load i8, i8* %5
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 43
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 45
br label %36
36: ; preds = %32, %28
%37 = phi i1 [ true, %28 ], [ %35, %32 ]
br label %38
38: ; preds = %36, %24
%39 = phi i1 [ false, %24 ], [ %37, %36 ]
br label %40
40: ; preds = %38, %20
%41 = phi i1 [ true, %20 ], [ %39, %38 ]
br i1 %41, label %42, label %65
42: ; preds = %40
%43 = load i8, i8* %7
%44 = sext i8 %43 to i32
switch i32 %44, label %58 [
i32 48, label %45
i32 49, label %45
i32 50, label %45
i32 51, label %45
i32 52, label %45
i32 53, label %45
i32 54, label %45
i32 55, label %45
i32 56, label %45
i32 57, label %45
i32 45, label %56
i32 43, label %57
]
45: ; preds = %42, %42, %42, %42, %42, %42, %42, %42, %42, %42
%46 = load i32, i32* %3
%47 = load i32, i32* %3
%48 = call i32 @mpz_mul_ui(i32 %46, i32 %47, i64 10)
%49 = load i32, i32* %3
%50 = load i32, i32* %3
%51 = load i8, i8* %7
%52 = sext i8 %51 to i32
%53 = sub nsw i32 %52, 48
%54 = sext i32 %53 to i64
%55 = call i32 @mpz_add_ui(i32 %49, i32 %50, i64 %54)
store i8 0, i8* %5
br label %58
56: ; preds = %42
store i8 1, i8* %6
br label %57
57: ; preds = %42, %56
store i8 0, i8* %5
br label %58
58: ; preds = %42, %57, %45
%59 = load i8*, i8** %4
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i8, i8* %63
store i8 %64, i8* %7
br label %16
65: ; preds = %40
%66 = load i8, i8* %6
%67 = icmp ne i8 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load i32, i32* %3
%70 = load i32, i32* %3
%71 = call i32 @mpz_neg(i32 %69, i32 %70)
br label %72
72: ; preds = %68, %65
%73 = load i32, i32* %8
ret i32 %73
}

LLVM IR (-O2):
define i32 @mpz_EGlpNumReadStr(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = tail call i32 @mpz_set_ui(i32 %0, i64 0)
br label %5
5: ; preds = %25, %2
%6 = phi i64 [ %28, %25 ], [ 0, %2 ]
%7 = phi i8 [ %26, %25 ], [ 1, %2 ]
%8 = phi i8 [ %27, %25 ], [ 0, %2 ]
%9 = phi i8 [ %30, %25 ], [ %3, %2 ]
%10 = sext i8 %9 to i32
%11 = add i8 %9, -48
%12 = icmp ult i8 %11, 10
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = icmp eq i8 %7, 0
br i1 %14, label %31, label %15
15: ; preds = %13
switch i8 %9, label %31 [
i8 45, label %16
i8 43, label %16
]
16: ; preds = %15, %15, %5
switch i32 %10, label %25 [
i32 48, label %17
i32 49, label %17
i32 50, label %17
i32 51, label %17
i32 52, label %17
i32 53, label %17
i32 54, label %17
i32 55, label %17
i32 56, label %17
i32 57, label %17
i32 45, label %22
i32 43, label %23
]
17: ; preds = %16, %16, %16, %16, %16, %16, %16, %16, %16, %16
%18 = tail call i32 @mpz_mul_ui(i32 %0, i32 %0, i64 10)
%19 = add nsw i32 %10, -48
%20 = zext i32 %19 to i64
%21 = tail call i32 @mpz_add_ui(i32 %0, i32 %0, i64 %20)
br label %25
22: ; preds = %16
br label %23
23: ; preds = %16, %22
%24 = phi i8 [ %8, %16 ], [ 1, %22 ]
br label %25
25: ; preds = %16, %23, %17
%26 = phi i8 [ %7, %16 ], [ 0, %23 ], [ 0, %17 ]
%27 = phi i8 [ %8, %16 ], [ %24, %23 ], [ %8, %17 ]
%28 = add nuw i64 %6, 1
%29 = getelementptr inbounds i8, i8* %1, i64 %28
%30 = load i8, i8* %29
br label %5
31: ; preds = %15, %13
%32 = icmp eq i8 %8, 0
br i1 %32, label %35, label %33
33: ; preds = %31
%34 = tail call i32 @mpz_neg(i32 %0, i32 %0)
br label %35
35: ; preds = %33, %31
%36 = trunc i64 %6 to i32
ret i32 %36
}