#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int transition_func(char, int);
int main() {
  char str[100];
  int s = 0, i = 0;
  printf("\nEnter String:");
  gets(str);
  printf("\nSteps taken by dfa");
  while (str[i] != '\0') {
    printf("\nFor state %d and input %c", s, str[i]);
    s = transition_func(str[i], s);
    if (s == -1)
      break;
    else {
      printf(",We move to %d", s);
      i = i + 1;
    }
  }
  if ((s != -1) && (s == 3))
    printf("\nString %s successfully accepted", str);
  else
    printf("\nString not accepted");
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1050 <gets@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11e5 <main+0xb5>
mov    -0x74(%rbp),%esi
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edx
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    -0x74(%rbp),%esi
movsbl %al,%edi
call   1030 <transition_func@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    11c6 <main+0x96>
jmp    11e5 <main+0xb5>
mov    -0x74(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1175 <main+0x45>
cmpl   $0xffffffff,-0x74(%rbp)
je     1210 <main+0xe0>
cmpl   $0x3,-0x74(%rbp)
jne    1210 <main+0xe0>
lea    -0x70(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121e <main+0xee>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1060 <gets@plt>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%al
test   %al,%al
je     11e0 <main+0xa0>
lea    0x1(%rsp),%rbx
lea    0xea2(%rip),%r15
lea    0xeb6(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl -0x1(%rbx),%edi
mov    %ebp,%esi
call   1040 <transition_func@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0xa0>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1190 <main+0x50>
cmp    $0x3,%ebp
jne    11e0 <main+0xa0>
lea    0xe79(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11ee <main+0xae>
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\0AEnter String:\00"
@.str.1 = [20 x i8] c"\0ASteps taken by dfa\00"
@.str.2 = [27 x i8] c"\0AFor state %d and input %c\00"
@.str.3 = [15 x i8] c",We move to %d\00"
@.str.4 = [33 x i8] c"\0AString %s successfully accepted\00"
@.str.5 = [21 x i8] c"\0AString not accepted\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %38, %0
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %9
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %22)
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i32, i32* %3
%29 = call i32 @transition_func(i8 signext %27, i32 %28)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %16
br label %39
33: ; preds = %16
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %38
38: ; preds = %33
br label %9
39: ; preds = %32, %9
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, -1
br i1 %41, label %42, label %48
42: ; preds = %39
%43 = load i32, i32* %3
%44 = icmp eq i32 %43, 3
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %50
48: ; preds = %42, %39
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"\0AEnter String:\00"
@.str.1 = [20 x i8] c"\0ASteps taken by dfa\00"
@.str.2 = [27 x i8] c"\0AFor state %d and input %c\00"
@.str.3 = [15 x i8] c",We move to %d\00"
@.str.4 = [33 x i8] c"\0AString %s successfully accepted\00"
@.str.5 = [21 x i8] c"\0AString not accepted\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %0, %18
%9 = phi i64 [ %20, %18 ], [ 0, %0 ]
%10 = phi i8 [ %22, %18 ], [ %6, %0 ]
%11 = phi i8* [ %21, %18 ], [ %2, %0 ]
%12 = phi i32 [ %16, %18 ], [ 0, %0 ]
%13 = sext i8 %10 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %13)
%15 = load i8, i8* %11
%16 = call i32 @transition_func(i8 signext %15, i32 %12)
%17 = icmp eq i32 %16, -1
br i1 %17, label %28, label %18
18: ; preds = %8
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%20 = add nuw i64 %9, 1
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %8
24: ; preds = %18
%25 = icmp eq i32 %16, 3
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %30
28: ; preds = %8, %0, %24
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
%31 = call i32 @putchar(i32 10)
ret i32 0
}