#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 *, ...);
size_t strlen(char *);
void print_reverse(char *s) {
  printf("Your word is %lu letters long\n", strlen(s));
  size_t len = strlen(s);
  char *t = s + len - 1;
  while (t >= s) {
    printf("%c", *t);
    t--;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rsi
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     1197 <print_reverse+0x77>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1163 <print_reverse+0x43>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_reverse>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0xebd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1181 <print_reverse+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rbx),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1170 <print_reverse+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Your word is %lu letters long\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @print_reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strlen(i8* %5)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %6)
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %3
%10 = load i8*, i8** %2
%11 = load i64, i64* %3
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %4
br label %14
14: ; preds = %18, %1
%15 = load i8*, i8** %4
%16 = load i8*, i8** %2
%17 = icmp uge i8* %15, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %4
br label %14
25: ; preds = %14
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Your word is %lu letters long\0A\00"
define void @print_reverse(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 %2)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ult i8* %6, %0
br i1 %7, label %15, label %8
8: ; preds = %1, %8
%9 = phi i8* [ %13, %8 ], [ %6, %1 ]
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = tail call i32 @putchar(i32 %11)
%13 = getelementptr inbounds i8, i8* %9, i64 -1
%14 = icmp ult i8* %13, %0
br i1 %14, label %15, label %8
15: ; preds = %8, %1
%16 = tail call i32 @putchar(i32 10)
ret void
}