#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 EOF;
int /*<<< orphan*/ error(int, char *);
int fscanf(int /*<<< orphan*/ *, char *, unsigned long *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isdigit(int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
unsigned long getint(FILE *fp) {
  int c;
  unsigned long i = 0;
  int rc;
  while ((c = getc(fp)) != EOF && !isdigit(c))
    if (c == '#')
      while ((c = getc(fp)) != EOF && !(c == 13 || c == 10))
        ;
  if (c != EOF) {
    ungetc(c, fp);
    rc = fscanf(fp, "%lu", &i);
    if (rc != 1)
      error(1, "fscanf: rc == 0!\n");
  }
  return i;
}


x86 assembly (clang, -O0):
<getint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e6d(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     1199 <getint+0x49>
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a9 <getint+0x59>
jmp    121a <getint+0xca>
cmpl   $0x23,-0xc(%rbp)
jne    1215 <getint+0xc5>
jmp    11b8 <getint+0x68>
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e19(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1e(%rbp)
je     11fb <getint+0xab>
mov    $0x1,%al
cmpl   $0xd,-0xc(%rbp)
mov    %al,-0x1f(%rbp)
je     11f3 <getint+0xa3>
cmpl   $0xa,-0xc(%rbp)
sete   %al
mov    %al,-0x1f(%rbp)
mov    -0x1f(%rbp),%al
xor    $0xff,%al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    120b <getint+0xbb>
jmp    1210 <getint+0xc0>
jmp    11b8 <getint+0x68>
jmp    1215 <getint+0xc5>
jmp    1164 <getint+0x14>
mov    -0xc(%rbp),%eax
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%eax
je     126f <getint+0x11f>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x8(%rbp),%rdi
lea    0xdbd(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     126a <getint+0x11a>
mov    $0x1,%edi
lea    0xd9f(%rip),%rsi
call   1060 <error@plt>
jmp    126f <getint+0x11f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getint>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
call   1060 <getc@plt>
mov    0x2e8d(%rip),%r14
mov    (%r14),%ecx
cmp    %ecx,%eax
je     11b9 <getint+0x79>
mov    %eax,%edx
add    $0xffffffc6,%edx
cmp    $0xfffffff5,%edx
ja     11b9 <getint+0x79>
nopl   0x0(%rax)
cmp    $0x23,%eax
jne    11a0 <getint+0x60>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <getc@plt>
cmp    (%r14),%eax
je     11a0 <getint+0x60>
cmp    $0xd,%eax
je     11a0 <getint+0x60>
cmp    $0xa,%eax
jne    1180 <getint+0x40>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    (%r14),%ecx
cmp    %ecx,%eax
je     11b9 <getint+0x79>
mov    %eax,%edx
add    $0xffffffc6,%edx
cmp    $0xfffffff6,%edx
jb     1170 <getint+0x30>
cmp    %ecx,%eax
je     11ef <getint+0xaf>
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <ungetc@plt>
lea    0xe32(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     11ef <getint+0xaf>
lea    0xe1f(%rip),%rsi
mov    $0x1,%edi
call   1050 <error@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [4 x i8] c"%lu\00"
@.str.1 = [18 x i8] c"fscanf: rc == 0!\0A\00"
define i64 @getint(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %2
store i64 0, i64* %4
br label %6
6: ; preds = %40, %1
%7 = load i32*, i32** %2
%8 = call i32 @getc(i32* %7)
store i32 %8, i32* %3
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load i32, i32* %3
%13 = call i32 @isdigit(i32 %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br label %16
16: ; preds = %11, %6
%17 = phi i1 [ false, %6 ], [ %15, %11 ]
br i1 %17, label %18, label %41
18: ; preds = %16
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 35
br i1 %20, label %21, label %40
21: ; preds = %18
br label %22
22: ; preds = %38, %21
%23 = load i32*, i32** %2
%24 = call i32 @getc(i32* %23)
store i32 %24, i32* %3
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %36
27: ; preds = %22
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 13
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, 10
br label %33
33: ; preds = %30, %27
%34 = phi i1 [ true, %27 ], [ %32, %30 ]
%35 = xor i1 %34, true
br label %36
36: ; preds = %33, %22
%37 = phi i1 [ false, %22 ], [ %35, %33 ]
br i1 %37, label %38, label %39
38: ; preds = %36
br label %22
39: ; preds = %36
br label %40
40: ; preds = %39, %18
br label %6
41: ; preds = %16
%42 = load i32, i32* %3
%43 = load i32, i32* @EOF
%44 = icmp ne i32 %42, %43
br i1 %44, label %45, label %56
45: ; preds = %41
%46 = load i32, i32* %3
%47 = load i32*, i32** %2
%48 = call i32 @ungetc(i32 %46, i32* %47)
%49 = load i32*, i32** %2
%50 = call i32 @fscanf(i32* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %4)
store i32 %50, i32* %5
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = call i32 @error(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %55
55: ; preds = %53, %45
br label %56
56: ; preds = %55, %41
%57 = load i64, i64* %4
ret i64 %57
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [4 x i8] c"%lu\00"
@.str.1 = [18 x i8] c"fscanf: rc == 0!\0A\00"
define i64 @getint(i32* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = tail call i32 @getc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
%7 = add i32 %4, -58
%8 = icmp ult i32 %7, -10
%9 = and i1 %6, %8
br i1 %9, label %10, label %25
10: ; preds = %1, %18
%11 = phi i32 [ %19, %18 ], [ %4, %1 ]
%12 = icmp eq i32 %11, 35
br i1 %12, label %13, label %18
13: ; preds = %10, %17
%14 = tail call i32 @getc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %18, label %17
17: ; preds = %13
switch i32 %14, label %13 [
i32 13, label %18
i32 10, label %18
]
18: ; preds = %17, %17, %13, %10
%19 = tail call i32 @getc(i32* %0)
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
%22 = add i32 %19, -58
%23 = icmp ult i32 %22, -10
%24 = and i1 %21, %23
br i1 %24, label %10, label %25
25: ; preds = %18, %1
%26 = phi i32 [ %4, %1 ], [ %19, %18 ]
%27 = phi i32 [ %5, %1 ], [ %20, %18 ]
%28 = icmp eq i32 %26, %27
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = tail call i32 @ungetc(i32 %26, i32* %0)
%31 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %2)
%32 = icmp eq i32 %31, 1
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = call i32 @error(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %29, %33, %25
%36 = load i64, i64* %2
ret i64 %36
}