#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*/ stringxy(char *, int, int);
int strlen(char *);
int fscanner(char *string) {
  int i = 0, j, k, ctr = 0;
  int length = 0;
  length = strlen(string) - 1;
  printf("\nforward scan %s", string);
  for (i = 0; i <= length; i++)
    for (j = i; j <= length; j++) {
      if (j >= i)
        stringxy(string, i, j);
      ctr++;
    }
  printf("\n");
  printf("count = %d\n", ctr);
  return (0);
}


x86 assembly (clang, -O0):
<fscanner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11dc <fscanner+0xac>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11c9 <fscanner+0x99>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11b2 <fscanner+0x82>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <stringxy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118b <fscanner+0x5b>
jmp    11ce <fscanner+0x9e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <fscanner+0x49>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fscanner>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0xea3(%rip),%rdi
xor    %r14d,%r14d
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,%r12d
jle    11ba <fscanner+0x7a>
xor    %r14d,%r14d
mov    %r12d,%r13d
xor    %ebp,%ebp
jmp    118f <fscanner+0x4f>
nopl   0x0(%rax)
add    %r13d,%r14d
add    $0x1,%ebp
add    $0xffffffff,%r13d
cmp    %r12d,%ebp
je     11ba <fscanner+0x7a>
mov    %ebp,%ebx
jmp    11a8 <fscanner+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
cmp    %ebx,%r12d
je     1180 <fscanner+0x40>
cmp    %ebp,%ebx
jb     11a0 <fscanner+0x60>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1060 <stringxy@plt>
jmp    11a0 <fscanner+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe46(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\0Aforward scan %s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [12 x i8] c"count = %d\0A\00"
define i32 @fscanner(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %7
%11 = load i8*, i8** %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 0, i32* %3
br label %13
13: ; preds = %39, %1
%14 = load i32, i32* %3
%15 = load i32, i32* %7
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = load i32, i32* %3
store i32 %18, i32* %4
br label %19
19: ; preds = %35, %17
%20 = load i32, i32* %4
%21 = load i32, i32* %7
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %19
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = call i32 @stringxy(i8* %28, i32 %29, i32 %30)
br label %32
32: ; preds = %27, %23
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %35
35: ; preds = %32
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %19
38: ; preds = %19
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %13
42: ; preds = %13
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"\0Aforward scan %s\00"
@.str.2 = [12 x i8] c"count = %d\0A\00"
define i32 @fscanner(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %1, %17
%6 = phi i32 [ %20, %17 ], [ %2, %1 ]
%7 = phi i32 [ %18, %17 ], [ 0, %1 ]
%8 = phi i32 [ %19, %17 ], [ 0, %1 ]
br label %9
9: ; preds = %5, %14
%10 = phi i32 [ %15, %14 ], [ %8, %5 ]
%11 = icmp ult i32 %10, %8
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @stringxy(i8* %0, i32 %8, i32 %10)
br label %14
14: ; preds = %12, %9
%15 = add nuw i32 %10, 1
%16 = icmp eq i32 %15, %2
br i1 %16, label %17, label %9
17: ; preds = %14
%18 = add i32 %7, %6
%19 = add nuw nsw i32 %8, 1
%20 = add i32 %6, -1
%21 = icmp eq i32 %19, %2
br i1 %21, label %22, label %5
22: ; preds = %17, %1
%23 = phi i32 [ 0, %1 ], [ %18, %17 ]
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i32 0
}