#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char temp;
  int currentState = 0, startState = 0, acceptState = 0, numStates = 0;
  printf("\nEnter the number of states.\n");
  scanf("%d", &numStates);
  printf("\nEnter the start state.\n");
  scanf("%d", &startState);
  printf("\nEnter the accept state.\n");
  scanf("%d", &acceptState);
  scanf("%c", &temp);
  currentState = startState;
  printf("\nPlease enter a number of 1s, followed by a 0.\n");
  while (1) {
    scanf("%c", &temp);
    if (temp == '0') {
      break;
    } else if (temp == '1') {
      currentState++;
      currentState = currentState % numStates;
    } else {
      printf("Illegal character.\n");
    }
  }
  if (currentState == acceptState) {
    printf("\nAccept.\n");
  } else {
    printf("\nReject.\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
lea    0xe84(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xea8(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
lea    0xe84(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jne    11ed <main+0xcd>
jmp    1228 <main+0x108>
movsbl -0x5(%rbp),%eax
cmp    $0x31,%eax
jne    1212 <main+0xf2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0xc(%rbp)
jmp    121e <main+0xfe>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
jmp    1223 <main+0x103>
jmp    11c9 <main+0xa9>
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1245 <main+0x125>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
jmp    1251 <main+0x131>
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeab(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xe62(%rip),%r14
lea    0xb(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%r15d
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movzbl 0xb(%rsp),%eax
cmp    $0x30,%al
je     1205 <main+0xe5>
cmp    $0x31,%al
je     11f4 <main+0xd4>
mov    %rbp,%rdi
call   1030 <puts@plt>
jmp    11d0 <main+0xb0>
add    $0x1,%r15d
mov    %r15d,%eax
cltd
idivl  0xc(%rsp)
mov    %edx,%r15d
jmp    11d0 <main+0xb0>
cmp    0x10(%rsp),%r15d
lea    0xe8e(%rip),%rax
lea    0xe7e(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"\0AEnter the number of states.\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"\0AEnter the start state.\0A\00"
@.str.3 = [26 x i8] c"\0AEnter the accept state.\0A\00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [48 x i8] c"\0APlease enter a number of 1s, followed by a 0.\0A\00"
@.str.6 = [20 x i8] c"Illegal character.\0A\00"
@.str.7 = [10 x i8] c"\0AAccept.\0A\00"
@.str.8 = [10 x i8] c"\0AReject.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%9 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%14 = load i32, i32* %4
store i32 %14, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %0, %35
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 48
br i1 %20, label %21, label %22
21: ; preds = %16
br label %36
22: ; preds = %16
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 49
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = load i32, i32* %6
%31 = srem i32 %29, %30
store i32 %31, i32* %3
br label %34
32: ; preds = %22
%33 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
br label %35
35: ; preds = %34
br label %16
36: ; preds = %21
%37 = load i32, i32* %3
%38 = load i32, i32* %5
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %44
42: ; preds = %36
%43 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %44
44: ; preds = %42, %40
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c"%c\00"
@str = [29 x i8] c"\0AEnter the number of states.\00"
@str.9 = [24 x i8] c"\0AEnter the start state.\00"
@str.10 = [25 x i8] c"\0AEnter the accept state.\00"
@str.11 = [47 x i8] c"\0APlease enter a number of 1s, followed by a 0.\00"
@str.12 = [19 x i8] c"Illegal character.\00"
@str.13 = [9 x i8] c"\0AReject.\00"
@str.14 = [9 x i8] c"\0AAccept.\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.9, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%15 = load i32, i32* %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.11, i64 0, i64 0))
br label %17
17: ; preds = %22, %0
%18 = phi i32 [ %25, %22 ], [ %15, %0 ]
br label %19
19: ; preds = %17, %26
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%21 = load i8, i8* %1
switch i8 %21, label %26 [
i8 48, label %28
i8 49, label %22
]
22: ; preds = %19
%23 = add nsw i32 %18, 1
%24 = load i32, i32* %4
%25 = srem i32 %23, %24
br label %17
26: ; preds = %19
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.12, i64 0, i64 0))
br label %19
28: ; preds = %19
%29 = load i32, i32* %3
%30 = icmp eq i32 %18, %29
%31 = select i1 %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.14, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str.13, i64 0, i64 0)
%32 = call i32 @puts(i8* dereferenceable(1) %31)
ret i32 0
}