#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 */
int getc(int /*<<< orphan*/ *);
int ignore_whitespace(int /*<<< orphan*/ *);
int read_dec(int /*<<< orphan*/ *, int *);
int read_hex(int /*<<< orphan*/ *, int *);
int /*<<< orphan*/ sysbuild_warning(char *, int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int read_int(FILE *config_fp, int *value) {
  int c1, c2, c3;
  *value = 0;
  c1 = ignore_whitespace(config_fp);
  if (!((c1) >= '0' && (c1) <= '9')) {
    sysbuild_warning("Found %c instead of a digit", c1);
    return 0;
  }
  c2 = getc(config_fp);
  c3 = getc(config_fp);
  if (c1 == '0' && c2 == 'x') {
    if ((((c3) >= '0' && (c3) <= '9') || ((c3) >= 'A' && (c3) <= 'F') ||
         ((c3) >= 'a' && (c3) <= 'f'))) {
      ungetc(c3, config_fp);
      return (read_hex(config_fp, value));
    } else {
      *value = 0;
      ungetc(c3, config_fp);
      ungetc(c2, config_fp);
      return 1;
    }
  } else {
    *value = (c1 - '0');
    ungetc(c3, config_fp);
    ungetc(c2, config_fp);
    return (read_dec(config_fp, value));
  }
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <ignore_whitespace@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x30,-0x1c(%rbp)
jl     119a <read_int+0x3a>
cmpl   $0x39,-0x1c(%rbp)
jle    11b5 <read_int+0x55>
mov    -0x1c(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1080 <sysbuild_warning@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <read_int+0x140>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x30,-0x1c(%rbp)
jne    126c <read_int+0x10c>
cmpl   $0x78,-0x20(%rbp)
jne    126c <read_int+0x10c>
cmpl   $0x30,-0x24(%rbp)
jl     11f5 <read_int+0x95>
cmpl   $0x39,-0x24(%rbp)
jle    121d <read_int+0xbd>
cmpl   $0x41,-0x24(%rbp)
jl     1209 <read_int+0xa9>
cmpl   $0x46,-0x24(%rbp)
jle    121d <read_int+0xbd>
cmpl   $0x61,-0x24(%rbp)
jl     123e <read_int+0xde>
cmpl   $0x66,-0x24(%rbp)
jg     123e <read_int+0xde>
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <read_hex@plt>
mov    %eax,-0x4(%rbp)
jmp    12a0 <read_int+0x140>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <read_int+0x140>
mov    -0x1c(%rbp),%ecx
sub    $0x30,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <read_dec@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,(%rsi)
call   1040 <ignore_whitespace@plt>
mov    %eax,%ebx
lea    -0x30(%rbx),%ebp
cmp    $0xa,%ebp
jae    11e0 <read_int+0x80>
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1070 <getc@plt>
cmp    $0x30,%ebx
jne    11f9 <read_int+0x99>
cmp    $0x78,%r12d
jne    11f9 <read_int+0x99>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jb     11c3 <read_int+0x63>
mov    %eax,%ecx
add    $0xffffffbf,%ecx
cmp    $0x25,%ecx
ja     1224 <read_int+0xc4>
movabs $0x3f0000003f,%rdx
bt     %rcx,%rdx
jae    1224 <read_int+0xc4>
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <ungetc@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <read_hex@plt>
lea    0xe19(%rip),%rdi
mov    %ebx,%esi
call   1080 <sysbuild_warning@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,(%r14)
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <ungetc@plt>
mov    %r12d,%edi
mov    %r15,%rsi
call   1050 <ungetc@plt>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <read_dec@plt>
movl   $0x0,(%r14)
mov    %eax,%edi
mov    %r15,%rsi
call   1050 <ungetc@plt>
mov    $0x78,%edi
mov    %r15,%rsi
call   1050 <ungetc@plt>
mov    $0x1,%eax
jmp    11f0 <read_int+0x90>

LLVM IR (-O0):
@.str = [28 x i8] c"Found %c instead of a digit\00"
define i32 @read_int(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %5
store i32 0, i32* %9
%10 = load i32*, i32** %4
%11 = call i32 @ignore_whitespace(i32* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp sge i32 %12, 48
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp sle i32 %15, 57
br i1 %16, label %20, label %17
17: ; preds = %14, %2
%18 = load i32, i32* %6
%19 = call i32 @sysbuild_warning(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 0, i32* %3
br label %76
20: ; preds = %14
%21 = load i32*, i32** %4
%22 = call i32 @getc(i32* %21)
store i32 %22, i32* %7
%23 = load i32*, i32** %4
%24 = call i32 @getc(i32* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 48
br i1 %26, label %27, label %63
27: ; preds = %20
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 120
br i1 %29, label %30, label %63
30: ; preds = %27
%31 = load i32, i32* %8
%32 = icmp sge i32 %31, 48
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp sle i32 %34, 57
br i1 %35, label %48, label %36
36: ; preds = %33, %30
%37 = load i32, i32* %8
%38 = icmp sge i32 %37, 65
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %8
%41 = icmp sle i32 %40, 70
br i1 %41, label %48, label %42
42: ; preds = %39, %36
%43 = load i32, i32* %8
%44 = icmp sge i32 %43, 97
br i1 %44, label %45, label %55
45: ; preds = %42
%46 = load i32, i32* %8
%47 = icmp sle i32 %46, 102
br i1 %47, label %48, label %55
48: ; preds = %45, %39, %33
%49 = load i32, i32* %8
%50 = load i32*, i32** %4
%51 = call i32 @ungetc(i32 %49, i32* %50)
%52 = load i32*, i32** %4
%53 = load i32*, i32** %5
%54 = call i32 @read_hex(i32* %52, i32* %53)
store i32 %54, i32* %3
br label %76
55: ; preds = %45, %42
%56 = load i32*, i32** %5
store i32 0, i32* %56
%57 = load i32, i32* %8
%58 = load i32*, i32** %4
%59 = call i32 @ungetc(i32 %57, i32* %58)
%60 = load i32, i32* %7
%61 = load i32*, i32** %4
%62 = call i32 @ungetc(i32 %60, i32* %61)
store i32 1, i32* %3
br label %76
63: ; preds = %27, %20
%64 = load i32, i32* %6
%65 = sub nsw i32 %64, 48
%66 = load i32*, i32** %5
store i32 %65, i32* %66
%67 = load i32, i32* %8
%68 = load i32*, i32** %4
%69 = call i32 @ungetc(i32 %67, i32* %68)
%70 = load i32, i32* %7
%71 = load i32*, i32** %4
%72 = call i32 @ungetc(i32 %70, i32* %71)
%73 = load i32*, i32** %4
%74 = load i32*, i32** %5
%75 = call i32 @read_dec(i32* %73, i32* %74)
store i32 %75, i32* %3
br label %76
76: ; preds = %63, %55, %48, %17
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [28 x i8] c"Found %c instead of a digit\00"
define i32 @read_int(i32* %0, i32* %1) {
store i32 0, i32* %1
%3 = tail call i32 @ignore_whitespace(i32* %0)
%4 = add i32 %3, -48
%5 = icmp ult i32 %4, 10
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @sysbuild_warning(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %3)
br label %28
8: ; preds = %2
%9 = tail call i32 @getc(i32* %0)
%10 = tail call i32 @getc(i32* %0)
%11 = icmp eq i32 %3, 48
%12 = icmp eq i32 %9, 120
%13 = and i1 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %8
%15 = add i32 %10, -48
%16 = icmp ult i32 %15, 10
br i1 %16, label %18, label %17
17: ; preds = %14
switch i32 %10, label %21 [
i32 102, label %18
i32 101, label %18
i32 100, label %18
i32 99, label %18
i32 98, label %18
i32 97, label %18
i32 70, label %18
i32 69, label %18
i32 68, label %18
i32 67, label %18
i32 66, label %18
i32 65, label %18
]
18: ; preds = %17, %17, %17, %17, %17, %17, %17, %17, %17, %17, %17, %17, %14
%19 = tail call i32 @ungetc(i32 %10, i32* %0)
%20 = tail call i32 @read_hex(i32* %0, i32* %1)
br label %28
21: ; preds = %17
store i32 0, i32* %1
%22 = tail call i32 @ungetc(i32 %10, i32* %0)
%23 = tail call i32 @ungetc(i32 120, i32* %0)
br label %28
24: ; preds = %8
store i32 %4, i32* %1
%25 = tail call i32 @ungetc(i32 %10, i32* %0)
%26 = tail call i32 @ungetc(i32 %9, i32* %0)
%27 = tail call i32 @read_dec(i32* %0, i32* %1)
br label %28
28: ; preds = %24, %21, %18, %6
%29 = phi i32 [ %20, %18 ], [ 1, %21 ], [ %27, %24 ], [ 0, %6 ]
ret i32 %29
}