#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 *, char);
int /*<<< orphan*/ puts(char *);
void printReversedString(char *string) {
  int i = 0;
  int len = 0;
  while (string[len] != '\0') {
    len++;
  }
  printf("[%d]\n", len);
  for (i = len - 2; i >= 0; i--) {
    printf("%c", string[i]);
  }
  puts(" ");
  return;
}


x86 assembly (clang, -O0):
<printReversedString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     115d <printReversedString+0x3d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <printReversedString+0x1a>
mov    -0x10(%rbp),%eax
lea    0xe99(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11a8 <printReversedString+0x88>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
lea    0xe75(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <printReversedString+0x58>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printReversedString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0xfffffffd,%ebp
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmpb   $0x0,0x1(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1140 <printReversedString+0x20>
movsbl %bl,%esi
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
test   $0xfffffffe,%ebx
je     1197 <printReversedString+0x77>
mov    %ebp,%eax
add    $0x1,%ebp
add    %rax,%r15
lea    0xe91(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%r15
test   %ebp,%ebp
jg     1180 <printReversedString+0x60>
lea    0xe6b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"[%d]\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c" \00"
define void @printReversedString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %13, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %5
16: ; preds = %5
%17 = load i32, i32* %4
%18 = trunc i32 %17 to i8
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 2
store i32 %21, i32* %3
br label %22
22: ; preds = %32, %16
%23 = load i32, i32* %3
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %30)
br label %32
32: ; preds = %25
%33 = load i32, i32* %3
%34 = add nsw i32 %33, -1
store i32 %34, i32* %3
br label %22
35: ; preds = %22
%36 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"[%d]\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c" \00"
define void @printReversedString(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %7, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
%7 = add nuw i64 %3, 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = trunc i64 %3 to i8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %9)
%11 = and i64 %3, 4294967294
%12 = icmp eq i64 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %8
%14 = add i64 %3, 4294967294
%15 = and i64 %14, 4294967295
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ %15, %13 ], [ %21, %16 ]
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %19)
%21 = add nsw i64 %17, -1
%22 = trunc i64 %17 to i32
%23 = icmp sgt i32 %22, 0
br i1 %23, label %16, label %24
24: ; preds = %16, %8
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}