#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*/ getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
int strlen(char *);
int main() {
  char *text = "abcd";
  char *p = text;
  p += strlen(p) - 1;
  while (text <= p) {
    puts(p--);
  }
  printf("\n[Press Enter to close]");
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
ja     11a7 <main+0x67>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
mov    %eax,%edi
call   1030 <puts@plt>
jmp    117e <main+0x3e>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1183 <main+0x43>
lea    -0x1(%rax),%ebx
add    %r14,%rbx
lea    (%rax,%r14,1),%ebp
add    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffffffffffff,%rbx
mov    %ebp,%edi
call   1030 <puts@plt>
add    $0xffffffff,%ebp
cmp    %r14,%rbx
jae    1170 <main+0x30>
lea    0xe7b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"abcd\00"
@.str.1 = [24 x i8] c"\0A[Press Enter to close]\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
%8 = load i8*, i8** %3
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %8, i64 %9
store i8* %10, i8** %3
br label %11
11: ; preds = %15, %0
%12 = load i8*, i8** %2
%13 = load i8*, i8** %3
%14 = icmp ule i8* %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %3
%18 = ptrtoint i8* %16 to i32
%19 = call i32 @puts(i32 %18)
br label %11
20: ; preds = %11
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"abcd\00"
@.str.1 = [24 x i8] c"\0A[Press Enter to close]\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp slt i32 %1, 1
br i1 %2, label %14, label %3
3: ; preds = %0
%4 = add nsw i32 %1, -1
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds [5 x i8], [5 x i8]* @.str, i64 0, i64 %5
br label %7
7: ; preds = %3, %7
%8 = phi i8* [ %9, %7 ], [ %6, %3 ]
%9 = getelementptr inbounds i8, i8* %8, i64 -1
%10 = ptrtoint i8* %8 to i64
%11 = trunc i64 %10 to i32
%12 = tail call i32 @puts(i32 %11)
%13 = icmp ult i8* %9, getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
br i1 %13, label %14, label %7
14: ; preds = %7, %0
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (...) @getchar()
ret i32 0
}