#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 /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
int read_num(FILE *fp) {
  char c;
  int num, finished = 0;
  do {
    c = getc(fp);
    if (c == '#')
      while ((c = getc(fp)) != '\n')
        ;
    else if ((c >= '0') && (c <= '9')) {
      ungetc(c, fp);
      fscanf(fp, "%d", &num);
      finished = 1;
    }
  } while (!finished);
  return num;
}


x86 assembly (clang, -O0):
<read_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x23,%eax
jne    1183 <read_num+0x53>
jmp    1161 <read_num+0x31>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     117e <read_num+0x4e>
jmp    1161 <read_num+0x31>
jmp    11cc <read_num+0x9c>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     11c7 <read_num+0x97>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jg     11c7 <read_num+0x97>
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
mov    -0x8(%rbp),%rdi
lea    0xe49(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1030 <fscanf@plt>
movl   $0x1,-0x14(%rbp)
jmp    11cc <read_num+0x9c>
jmp    11d1 <read_num+0xa1>
cmpl   $0x0,-0x14(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1143 <read_num+0x13>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_num>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
jmp    1148 <read_num+0x18>
nopw   0x0(%rax,%rax,1)
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
jbe    116e <read_num+0x3e>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    $0x23,%al
jne    1140 <read_num+0x10>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    $0xa,%al
jne    1160 <read_num+0x30>
jmp    1148 <read_num+0x18>
movsbl %al,%edi
mov    %rbx,%rsi
call   1040 <ungetc@plt>
lea    0xe80(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1030 <fscanf@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @read_num(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %5
br label %6
6: ; preds = %36, %1
%7 = load i32*, i32** %2
%8 = call signext i8 @getc(i32* %7)
store i8 %8, i8* %3
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 35
br i1 %11, label %12, label %20
12: ; preds = %6
br label %13
13: ; preds = %18, %12
%14 = load i32*, i32** %2
%15 = call signext i8 @getc(i32* %14)
store i8 %15, i8* %3
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %19
18: ; preds = %13
br label %13
19: ; preds = %13
br label %35
20: ; preds = %6
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp sge i32 %22, 48
br i1 %23, label %24, label %34
24: ; preds = %20
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = icmp sle i32 %26, 57
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i8, i8* %3
%30 = load i32*, i32** %2
%31 = call i32 @ungetc(i8 signext %29, i32* %30)
%32 = load i32*, i32** %2
%33 = call i32 @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
store i32 1, i32* %5
br label %34
34: ; preds = %28, %24, %20
br label %35
35: ; preds = %34, %19
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
br i1 %39, label %6, label %40
40: ; preds = %36
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @read_num(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %13, %1
%5 = tail call signext i8 @getc(i32* %0)
%6 = icmp eq i8 %5, 35
br i1 %6, label %7, label %10
7: ; preds = %4, %7
%8 = tail call signext i8 @getc(i32* %0)
%9 = icmp eq i8 %8, 10
br i1 %9, label %13, label %7
10: ; preds = %4
%11 = add i8 %5, -48
%12 = icmp ult i8 %11, 10
br i1 %12, label %14, label %13
13: ; preds = %7, %10
br label %4
14: ; preds = %10
%15 = tail call i32 @ungetc(i8 signext %5, i32* %0)
%16 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%17 = load i32, i32* %2
ret i32 %17
}