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

/* Variables and functions */
scalar_t__ __digit(char, int);
scalar_t__ __isbdigit(char, int);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
unsigned int __scan_uint(FILE *stream, int width, int flags) {
  int base;
  char c;
  unsigned int value;
  if (flags & 0x01)
    base = 10;
  else if (flags & 0x02)
    base = 16;
  else if (flags & 0x04)
    base = 8;
  else {
    c = getc(stream);
    if (c == '0') {
      width--;
      c = getc(stream);
      if (c == 'x' || c == 'X') {
        width--;
        base = 16;
      } else {
        base = 8;
      }
    } else {
      ungetc(c, stream);
      base = 10;
    }
  }
  value = 0;
  while (__isbdigit((c = getc(stream)), base)) {
    value *= base;
    value += __digit(c, base);
    width--;
    if (width == 0) {
      return value;
    }
  }
  ungetc(c, stream);
  return value;
}


x86 assembly (clang, -O0):
<__scan_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     116d <__scan_uint+0x2d>
movl   $0xa,-0x1c(%rbp)
jmp    1231 <__scan_uint+0xf1>
mov    -0x18(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1188 <__scan_uint+0x48>
movl   $0x10,-0x1c(%rbp)
jmp    122c <__scan_uint+0xec>
mov    -0x18(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11a3 <__scan_uint+0x63>
movl   $0x8,-0x1c(%rbp)
jmp    1227 <__scan_uint+0xe7>
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x30,%eax
jne    120c <__scan_uint+0xcc>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x78,%eax
je     11eb <__scan_uint+0xab>
movsbl -0x1d(%rbp),%eax
cmp    $0x58,%eax
jne    1200 <__scan_uint+0xc0>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
movl   $0x10,-0x1c(%rbp)
jmp    1207 <__scan_uint+0xc7>
movl   $0x8,-0x1c(%rbp)
jmp    1222 <__scan_uint+0xe2>
mov    -0x1d(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
movl   $0xa,-0x1c(%rbp)
jmp    1227 <__scan_uint+0xe7>
jmp    122c <__scan_uint+0xec>
jmp    1231 <__scan_uint+0xf1>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x1d(%rbp)
mov    -0x1c(%rbp),%esi
movsbl %al,%edi
call   1050 <__isbdigit@plt>
cmp    $0x0,%rax
je     12a0 <__scan_uint+0x160>
mov    -0x1c(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1d(%rbp),%al
mov    -0x1c(%rbp),%esi
movsbl %al,%edi
call   1030 <__digit@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    129b <__scan_uint+0x15b>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b5 <__scan_uint+0x175>
jmp    1238 <__scan_uint+0xf8>
mov    -0x1d(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__scan_uint>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
mov    $0xa,%r15d
test   $0x1,%dl
jne    11a6 <__scan_uint+0x66>
mov    $0x10,%r15d
test   $0x2,%dl
jne    11a6 <__scan_uint+0x66>
test   $0x4,%dl
jne    11a0 <__scan_uint+0x60>
mov    %r14,%rdi
call   1060 <getc@plt>
cmp    $0x30,%al
jne    1189 <__scan_uint+0x49>
mov    %r14,%rdi
call   1060 <getc@plt>
and    $0xdf,%al
cmp    $0x58,%al
jne    119c <__scan_uint+0x5c>
add    $0xfffffffe,%r12d
jmp    11a6 <__scan_uint+0x66>
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <ungetc@plt>
mov    $0xa,%r15d
jmp    11a6 <__scan_uint+0x66>
add    $0xffffffff,%r12d
mov    $0x8,%r15d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <getc@plt>
movsbl %al,%ebx
mov    %ebx,%edi
mov    %r15d,%esi
call   1050 <__isbdigit@plt>
test   %rax,%rax
je     11e4 <__scan_uint+0xa4>
imul   %r15d,%ebp
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <__digit@plt>
add    %ebp,%eax
mov    %eax,%ebp
add    $0xffffffff,%r12d
jne    11b0 <__scan_uint+0x70>
jmp    11f0 <__scan_uint+0xb0>
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <ungetc@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__scan_uint(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = and i32 %11, 1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 10, i32* %8
br label %55
15: ; preds = %3
%16 = load i32, i32* %7
%17 = and i32 %16, 2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 16, i32* %8
br label %54
20: ; preds = %15
%21 = load i32, i32* %7
%22 = and i32 %21, 4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 8, i32* %8
br label %53
25: ; preds = %20
%26 = load i32*, i32** %5
%27 = call signext i8 @getc(i32* %26)
store i8 %27, i8* %9
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 48
br i1 %30, label %31, label %48
31: ; preds = %25
%32 = load i32, i32* %6
%33 = add nsw i32 %32, -1
store i32 %33, i32* %6
%34 = load i32*, i32** %5
%35 = call signext i8 @getc(i32* %34)
store i8 %35, i8* %9
%36 = load i8, i8* %9
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 120
br i1 %38, label %43, label %39
39: ; preds = %31
%40 = load i8, i8* %9
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 88
br i1 %42, label %43, label %46
43: ; preds = %39, %31
%44 = load i32, i32* %6
%45 = add nsw i32 %44, -1
store i32 %45, i32* %6
store i32 16, i32* %8
br label %47
46: ; preds = %39
store i32 8, i32* %8
br label %47
47: ; preds = %46, %43
br label %52
48: ; preds = %25
%49 = load i8, i8* %9
%50 = load i32*, i32** %5
%51 = call i32 @ungetc(i8 signext %49, i32* %50)
store i32 10, i32* %8
br label %52
52: ; preds = %48, %47
br label %53
53: ; preds = %52, %24
br label %54
54: ; preds = %53, %19
br label %55
55: ; preds = %54, %14
store i32 0, i32* %10
br label %56
56: ; preds = %79, %55
%57 = load i32*, i32** %5
%58 = call signext i8 @getc(i32* %57)
store i8 %58, i8* %9
%59 = load i32, i32* %8
%60 = call i64 @__isbdigit(i8 signext %58, i32 %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %80
62: ; preds = %56
%63 = load i32, i32* %8
%64 = load i32, i32* %10
%65 = mul i32 %64, %63
store i32 %65, i32* %10
%66 = load i8, i8* %9
%67 = load i32, i32* %8
%68 = call i64 @__digit(i8 signext %66, i32 %67)
%69 = load i32, i32* %10
%70 = zext i32 %69 to i64
%71 = add nsw i64 %70, %68
%72 = trunc i64 %71 to i32
store i32 %72, i32* %10
%73 = load i32, i32* %6
%74 = add nsw i32 %73, -1
store i32 %74, i32* %6
%75 = load i32, i32* %6
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %62
%78 = load i32, i32* %10
store i32 %78, i32* %4
br label %85
79: ; preds = %62
br label %56
80: ; preds = %56
%81 = load i8, i8* %9
%82 = load i32*, i32** %5
%83 = call i32 @ungetc(i8 signext %81, i32* %82)
%84 = load i32, i32* %10
store i32 %84, i32* %4
br label %85
85: ; preds = %80, %77
%86 = load i32, i32* %4
ret i32 %86
}

LLVM IR (-O2):
define i32 @__scan_uint(i32* nocapture %0, i32 %1, i32 %2) {
%4 = and i32 %2, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %3
%7 = and i32 %2, 2
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %6
%10 = and i32 %2, 4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = tail call signext i8 @getc(i32* %0)
%14 = icmp eq i8 %13, 48
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = tail call signext i8 @getc(i32* %0)
%17 = and i8 %16, -33
%18 = icmp eq i8 %17, 88
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = add nsw i32 %1, -2
br label %25
21: ; preds = %15
%22 = add nsw i32 %1, -1
br label %25
23: ; preds = %12
%24 = tail call i32 @ungetc(i8 signext %13, i32* %0)
br label %25
25: ; preds = %9, %6, %3, %23, %21, %19
%26 = phi i32 [ %20, %19 ], [ %22, %21 ], [ %1, %23 ], [ %1, %3 ], [ %1, %6 ], [ %1, %9 ]
%27 = phi i32 [ 16, %19 ], [ 8, %21 ], [ 10, %23 ], [ 10, %3 ], [ 16, %6 ], [ 8, %9 ]
br label %28
28: ; preds = %34, %25
%29 = phi i32 [ %26, %25 ], [ %39, %34 ]
%30 = phi i32 [ 0, %25 ], [ %38, %34 ]
%31 = tail call signext i8 @getc(i32* %0)
%32 = tail call i64 @__isbdigit(i8 signext %31, i32 %27)
%33 = icmp eq i64 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %28
%35 = mul i32 %30, %27
%36 = tail call i64 @__digit(i8 signext %31, i32 %27)
%37 = trunc i64 %36 to i32
%38 = add i32 %35, %37
%39 = add nsw i32 %29, -1
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %28
41: ; preds = %28
%42 = tail call i32 @ungetc(i8 signext %31, i32* %0)
br label %43
43: ; preds = %34, %41
%44 = phi i32 [ %30, %41 ], [ %38, %34 ]
ret i32 %44
}