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


x86 assembly (clang, -O0):
<diranner>:
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>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d3 <diranner+0xa3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11c0 <diranner+0x90>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11ad <diranner+0x7d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <stringxy@plt>
jmp    11b2 <diranner+0x82>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1188 <diranner+0x58>
jmp    11c5 <diranner+0x95>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <diranner+0x48>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diranner>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xea7(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jle    1198 <diranner+0x58>
mov    %r14d,%ebp
add    $0xffffffff,%ebp
jmp    1179 <diranner+0x39>
lea    -0x1(%rbp),%eax
test   %ebp,%ebp
mov    %eax,%ebp
jle    1198 <diranner+0x58>
mov    %r14d,%ebx
jmp    1185 <diranner+0x45>
xchg   %ax,%ax
add    $0xffffffff,%ebx
jle    1170 <diranner+0x30>
lea    -0x1(%rbx),%edx
cmp    %ebp,%edx
jl     1180 <diranner+0x40>
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <stringxy@plt>
jmp    1180 <diranner+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\0Abackward scan %s\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @diranner(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 ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %7
store i32 %13, i32* %3
br label %14
14: ; preds = %36, %1
%15 = load i32, i32* %3
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = load i32, i32* %7
store i32 %18, i32* %4
br label %19
19: ; preds = %32, %17
%20 = load i32, i32* %4
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i32, i32* %4
%24 = load i32, i32* %3
%25 = icmp sge i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %2
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = call i32 @stringxy(i8* %27, i32 %28, i32 %29)
br label %31
31: ; preds = %26, %22
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, -1
store i32 %34, i32* %4
br label %19
35: ; preds = %19
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = add nsw i32 %37, -1
store i32 %38, i32* %3
br label %14
39: ; preds = %14
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

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