#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 BUFSIZ;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sscanf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned int get_num_states(FILE *rfile) {
  char line[BUFSIZ];
  unsigned int linenum = 0;
  char id_str[BUFSIZ];
  unsigned int nstates = 0;
  unsigned int nstates_tmp;
  while (fgets(line, BUFSIZ, rfile) != NULL) {
    linenum++;
    if (line[0] == '#') {
      continue;
    }
    if (sscanf(line, "%s", id_str) < 1) {
      fprintf(stderr, "get_num_states: Syntax error, line %u.\n", linenum);
      return 0;
    }
    nstates_tmp = strtoul(id_str, NULL, 0) + 1;
    if (nstates_tmp != nstates + 1) {
      fprintf(stderr, "get_num_states: States are missing or out of order.\n");
      return 0;
    }
    nstates = nstates_tmp;
  }
  return nstates;
}


x86 assembly (clang, -O0):
<get_num_states>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x50(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     1287 <get_num_states+0x147>
mov    -0x50(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11e2 <get_num_states+0xa2>
jmp    11a4 <get_num_states+0x64>
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jge    122c <get_num_states+0xec>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1294 <get_num_states+0x154>
mov    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     127c <get_num_states+0x13c>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1294 <get_num_states+0x154>
mov    -0x38(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11a4 <get_num_states+0x64>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num_states>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    0x2e7d(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
xor    %ebx,%ebx
lea    0xe7b(%rip),%r13
movl   $0x0,-0x2c(%rbp)
nopl   0x0(%rax)
mov    (%r14),%esi
mov    %r12,%rdi
mov    %r15,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11fd <get_num_states+0xbd>
add    $0x1,%ebx
cmpb   $0x23,(%r12)
je     1190 <get_num_states+0x50>
mov    %r12,%rdi
mov    %r13,%rsi
mov    -0x38(%rbp),%r13
mov    %r13,%rdx
call   1050 <sscanf@plt>
test   %eax,%eax
jle    1213 <get_num_states+0xd3>
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
lea    0x1(%rax),%ecx
cmp    -0x2c(%rbp),%eax
mov    %ecx,-0x2c(%rbp)
lea    0xe21(%rip),%r13
je     1190 <get_num_states+0x50>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1201 <get_num_states+0xc1>
mov    -0x2c(%rbp),%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
xor    %r13d,%r13d
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1201 <get_num_states+0xc1>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"get_num_states: Syntax error, line %u.\0A\00"
@.str.2 = [53 x i8] c"get_num_states: States are missing or out of order.\0A\00"
define i32 @get_num_states(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %3
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
store i32 0, i32* %6
%15 = load i32, i32* @BUFSIZ
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
store i64 %16, i64* %7
store i32 0, i32* %8
br label %18
18: ; preds = %48, %30, %1
%19 = load i32, i32* @BUFSIZ
%20 = load i32*, i32** %3
%21 = call i32* @fgets(i8* %14, i32 %19, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %50
23: ; preds = %18
%24 = load i32, i32* %6
%25 = add i32 %24, 1
store i32 %25, i32* %6
%26 = getelementptr inbounds i8, i8* %14, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 35
br i1 %29, label %30, label %31
30: ; preds = %23
br label %18
31: ; preds = %23
%32 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i32, i32* %6
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %36)
store i32 0, i32* %2
store i32 1, i32* %10
br label %52
38: ; preds = %31
%39 = call i32 @strtoul(i8* %17, i32* null, i32 0)
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = load i32, i32* %8
%43 = add i32 %42, 1
%44 = icmp ne i32 %41, %43
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
store i32 1, i32* %10
br label %52
48: ; preds = %38
%49 = load i32, i32* %9
store i32 %49, i32* %8
br label %18
50: ; preds = %18
%51 = load i32, i32* %8
store i32 %51, i32* %2
store i32 1, i32* %10
br label %52
52: ; preds = %50, %45, %34
%53 = load i8*, i8** %4
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"get_num_states: Syntax error, line %u.\0A\00"
@.str.2 = [53 x i8] c"get_num_states: States are missing or out of order.\0A\00"
define i32 @get_num_states(i32* nocapture %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = alloca i8, i64 %3
br label %6
6: ; preds = %24, %1
%7 = phi i32 [ %15, %24 ], [ 0, %1 ]
%8 = phi i32 [ %27, %24 ], [ 0, %1 ]
br label %9
9: ; preds = %6, %14
%10 = phi i32 [ %15, %14 ], [ %7, %6 ]
%11 = load i32, i32* @BUFSIZ
%12 = call i32* @fgets(i8* %4, i32 %11, i32* %0)
%13 = icmp eq i32* %12, null
br i1 %13, label %31, label %14
14: ; preds = %9
%15 = add i32 %10, 1
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 35
br i1 %17, label %9, label %18
18: ; preds = %14
%19 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %31
24: ; preds = %18
%25 = call i32 @strtoul(i8* nocapture %5, i32* null, i32 0)
%26 = icmp eq i32 %25, %8
%27 = add nsw i32 %25, 1
br i1 %26, label %6, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %9, %28, %21
%32 = phi i32 [ 0, %21 ], [ 0, %28 ], [ %8, %9 ]
ret i32 %32
}