#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 /*<<< orphan*/ isdigit(int);
int scanc();
int /*<<< orphan*/ unscanc(int);
int /*<<< orphan*/ yyerror(char *);
int scan_dec_byte(void) {
  int c1, c2, c3;
  int b;
  c1 = scanc();
  if (!isdigit(c1)) {
    yyerror("malformed decimal digit");
    return (0);
  }
  b = c1 - '0';
  c2 = scanc();
  if (!isdigit(c2)) {
    yyerror("malformed decimal digit");
    return (0);
  }
  b *= 10;
  b += (c2 - '0');
  c3 = scanc();
  if (!isdigit(c3)) {
    unscanc(c3);
  } else {
    b *= 10;
    b += (c3 - '0');
  }
  return (b);
}


x86 assembly (clang, -O0):
<scan_dec_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <scanc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    117b <scan_dec_byte+0x3b>
lea    0xe96(%rip),%rdi
call   1040 <yyerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    120b <scan_dec_byte+0xcb>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <scanc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11b7 <scan_dec_byte+0x77>
lea    0xe5a(%rip),%rdi
call   1040 <yyerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    120b <scan_dec_byte+0xcb>
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <scanc@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11f2 <scan_dec_byte+0xb2>
mov    -0x10(%rbp),%edi
call   1050 <unscanc@plt>
jmp    1205 <scan_dec_byte+0xc5>
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x30,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_dec_byte>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <scanc@plt>
mov    %eax,%ebx
lea    -0x30(%rbx),%eax
cmp    $0xa,%eax
jae    1181 <scan_dec_byte+0x51>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <scanc@plt>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jae    1181 <scan_dec_byte+0x51>
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%r14d
add    $0xfffffdf0,%r14d
xor    %eax,%eax
call   1050 <scanc@plt>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jae    1198 <scan_dec_byte+0x68>
lea    (%r14,%r14,4),%eax
lea    (%rcx,%rax,2),%r14d
jmp    118d <scan_dec_byte+0x5d>
lea    0xe78(%rip),%rdi
call   1030 <yyerror@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %eax,%edi
call   1040 <unscanc@plt>
jmp    118d <scan_dec_byte+0x5d>

LLVM IR (-O0):
@.str = [24 x i8] c"malformed decimal digit\00"
define i32 @scan_dec_byte() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (...) @scanc()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @isdigit(i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @yyerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %44
12: ; preds = %0
%13 = load i32, i32* %2
%14 = sub nsw i32 %13, 48
store i32 %14, i32* %5
%15 = call i32 (...) @scanc()
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 @isdigit(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = call i32 @yyerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %44
21: ; preds = %12
%22 = load i32, i32* %5
%23 = mul nsw i32 %22, 10
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = sub nsw i32 %24, 48
%26 = load i32, i32* %5
%27 = add nsw i32 %26, %25
store i32 %27, i32* %5
%28 = call i32 (...) @scanc()
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = call i32 @isdigit(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %21
%33 = load i32, i32* %4
%34 = call i32 @unscanc(i32 %33)
br label %42
35: ; preds = %21
%36 = load i32, i32* %5
%37 = mul nsw i32 %36, 10
store i32 %37, i32* %5
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 48
%40 = load i32, i32* %5
%41 = add nsw i32 %40, %39
store i32 %41, i32* %5
br label %42
42: ; preds = %35, %32
%43 = load i32, i32* %5
store i32 %43, i32* %1
br label %44
44: ; preds = %42, %19, %10
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [24 x i8] c"malformed decimal digit\00"
define i32 @scan_dec_byte() {
%1 = tail call i32 (...) @scanc()
%2 = add i32 %1, -48
%3 = icmp ult i32 %2, 10
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @yyerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %24
6: ; preds = %0
%7 = tail call i32 (...) @scanc()
%8 = add i32 %7, -48
%9 = icmp ult i32 %8, 10
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 @yyerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %24
12: ; preds = %6
%13 = mul nuw nsw i32 %1, 10
%14 = add nsw i32 %13, -528
%15 = add nsw i32 %14, %7
%16 = tail call i32 (...) @scanc()
%17 = add i32 %16, -48
%18 = icmp ult i32 %17, 10
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = tail call i32 @unscanc(i32 %16)
br label %24
21: ; preds = %12
%22 = mul nuw nsw i32 %15, 10
%23 = add nuw nsw i32 %17, %22
br label %24
24: ; preds = %19, %21, %10, %4
%25 = phi i32 [ 0, %10 ], [ 0, %4 ], [ %23, %21 ], [ %15, %19 ]
ret i32 %25
}