#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 const EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int getc(int /*<<< orphan*/ *);
scalar_t__ isdigit(int const);
int /*<<< orphan*/ ungetc(int const, int /*<<< orphan*/ *);
int read_optional_number(FILE *f) {
  int num = -1;
  const int c = getc(f);
  if (c != EOF) {
    ungetc(c, f);
    if (isdigit(c) || c == '-' || c == '+') {
      const int nread = fscanf(f, "%30d\n", &num);
      assert(nread == 1 && "Wrong number of read numbers.");
      (void)nread;
    }
  }
  return num;
}


x86 assembly (clang, -O0):
<read_optional_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%eax
je     11f5 <read_optional_number+0xa5>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1060 <ungetc@plt>
mov    -0x10(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11b3 <read_optional_number+0x63>
cmpl   $0x2d,-0x10(%rbp)
je     11b3 <read_optional_number+0x63>
cmpl   $0x2b,-0x10(%rbp)
jne    11f0 <read_optional_number+0xa0>
mov    -0x8(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jne    11e3 <read_optional_number+0x93>
mov    $0x1,%al
mov    %al,-0x15(%rbp)
jmp    11e3 <read_optional_number+0x93>
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
jmp    11f5 <read_optional_number+0xa5>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_optional_number>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0xffffffff,0xc(%rsp)
ff
call   1070 <getc@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
je     11b1 <read_optional_number+0x61>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <ungetc@plt>
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11bd <read_optional_number+0x6d>
lea    0xe73(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <fscanf@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
mov    0xc(%rsp),%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
cmp    $0x2d,%ebp
je     118a <read_optional_number+0x3a>
cmp    $0x2b,%ebp
je     118a <read_optional_number+0x3a>
jmp    11b1 <read_optional_number+0x61>

LLVM IR (-O0):
@EOF = constant i32 0
@.str = [6 x i8] c"%30d\0A\00"
@.str.1 = [30 x i8] c"Wrong number of read numbers.\00"
define i32 @read_optional_number(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
store i32 -1, i32* %3
%6 = load i32*, i32** %2
%7 = call i32 @getc(i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %36
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32*, i32** %2
%14 = call i32 @ungetc(i32 %12, i32* %13)
%15 = load i32, i32* %4
%16 = call i64 @isdigit(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 45
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 43
br i1 %23, label %24, label %35
24: ; preds = %21, %18, %11
%25 = load i32*, i32** %2
%26 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %24
br label %30
30: ; preds = %29, %24
%31 = phi i1 [ false, %24 ], [ true, %29 ]
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32, i32* %5
br label %35
35: ; preds = %30, %21
br label %36
36: ; preds = %35, %1
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@EOF = constant i32 0
@.str = [6 x i8] c"%30d\0A\00"
define i32 @read_optional_number(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%4 = tail call i32 @getc(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = tail call i32 @ungetc(i32 %4, i32* %0)
%8 = tail call i64 @isdigit(i32 %4)
%9 = freeze i64 %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
switch i32 %4, label %18 [
i32 45, label %12
i32 43, label %12
]
12: ; preds = %11, %11, %6
%13 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = icmp eq i32 %13, 1
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* %2
br label %18
18: ; preds = %11, %12, %1
%19 = phi i32 [ -1, %11 ], [ %17, %12 ], [ -1, %1 ]
ret i32 %19
}