#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 */
struct bint {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bint_digit_push(struct bint *, int, char const);
int /*<<< orphan*/ bint_set(struct bint *, int /*<<< orphan*/);
int /*<<< orphan*/ bint_set_sign(struct bint *, int);
int /*<<< orphan*/ check(struct bint *);
scalar_t__ isdigit(char const);
void parse_num(const char *num, struct bint *out) {
  int negative = 0;
  bint_set(out, 0);
  check(out);
  while (*num) {
    if (*num == '-')
      negative = 1;
    else if (isdigit(*num))
      bint_digit_push(out, 10, *num - '0');
    num++;
    check(out);
  }
  bint_set_sign(out, negative ? -1 : 1);
  check(out);
}


x86 assembly (clang, -O0):
<parse_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <bint_set@plt>
mov    -0x10(%rbp),%rdi
call   1060 <check@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f4 <parse_num+0xa4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11a4 <parse_num+0x54>
movl   $0x1,-0x14(%rbp)
jmp    11da <parse_num+0x8a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d5 <parse_num+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    $0xa,%esi
movsbl %al,%edx
call   1040 <bint_digit_push@plt>
jmp    11da <parse_num+0x8a>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <check@plt>
jmp    117b <parse_num+0x2b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x1,%esi
mov    $0xffffffff,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
call   1070 <bint_set_sign@plt>
mov    -0x10(%rbp),%rdi
call   1060 <check@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_num>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
mov    %rsi,%rdi
xor    %esi,%esi
call   1050 <bint_set@plt>
jmp    1178 <parse_num+0x28>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
add    $0x1,%rbx
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <check@plt>
movzbl (%rbx),%ecx
mov    $0x1,%eax
cmp    $0x2d,%cl
je     1172 <parse_num+0x22>
test   %cl,%cl
je     11b5 <parse_num+0x65>
movsbl %cl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1170 <parse_num+0x20>
movzbl (%rbx),%eax
add    $0xd0,%al
movsbl %al,%edx
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <bint_digit_push@plt>
jmp    1170 <parse_num+0x20>
neg    %ebp
sbb    %esi,%esi
or     $0x1,%esi
mov    %r14,%rdi
call   1070 <bint_set_sign@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <check@plt>

LLVM IR (-O0):
%struct.bint = type { i32 }
define void @parse_num(i8* %0, %struct.bint* %1) {
%3 = alloca i8*
%4 = alloca %struct.bint*
%5 = alloca i32
store i8* %0, i8** %3
store %struct.bint* %1, %struct.bint** %4
store i32 0, i32* %5
%6 = load %struct.bint*, %struct.bint** %4
%7 = call i32 @bint_set(%struct.bint* %6, i32 0)
%8 = load %struct.bint*, %struct.bint** %4
%9 = call i32 @check(%struct.bint* %8)
br label %10
10: ; preds = %34, %2
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 45
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 1, i32* %5
br label %34
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = call i64 @isdigit(i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load %struct.bint*, %struct.bint** %4
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 48
%31 = trunc i32 %30 to i8
%32 = call i32 @bint_digit_push(%struct.bint* %26, i32 10, i8 signext %31)
br label %33
33: ; preds = %25, %20
br label %34
34: ; preds = %33, %19
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
%37 = load %struct.bint*, %struct.bint** %4
%38 = call i32 @check(%struct.bint* %37)
br label %10
39: ; preds = %10
%40 = load %struct.bint*, %struct.bint** %4
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, 0
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 -1, i32 1
%45 = call i32 @bint_set_sign(%struct.bint* %40, i32 %44)
%46 = load %struct.bint*, %struct.bint** %4
%47 = call i32 @check(%struct.bint* %46)
ret void
}

LLVM IR (-O2):
%struct.bint = type { i32 }
define void @parse_num(i8* nocapture %0, %struct.bint* %1) {
%3 = tail call i32 @bint_set(%struct.bint* %1, i32 0)
br label %4
4: ; preds = %16, %2
%5 = phi i8* [ %0, %2 ], [ %18, %16 ]
%6 = phi i32 [ 0, %2 ], [ %17, %16 ]
%7 = tail call i32 @check(%struct.bint* %1)
%8 = load i8, i8* %5
switch i8 %8, label %9 [
i8 0, label %19
i8 45, label %16
]
9: ; preds = %4
%10 = tail call i64 @isdigit(i8 signext %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = load i8, i8* %5
%14 = add i8 %13, -48
%15 = tail call i32 @bint_digit_push(%struct.bint* %1, i32 10, i8 signext %14)
br label %16
16: ; preds = %4, %9, %12
%17 = phi i32 [ %6, %12 ], [ %6, %9 ], [ 1, %4 ]
%18 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
19: ; preds = %4
%20 = icmp eq i32 %6, 0
%21 = select i1 %20, i32 1, i32 -1
%22 = tail call i32 @bint_set_sign(%struct.bint* %1, i32 %21)
%23 = tail call i32 @check(%struct.bint* %1)
ret void
}