#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*/ flushall();
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ putchar(int /*<<< orphan*/);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
int strlen(char *);
void main() {
  char *q = "abcd";
  while (*q)
    putchar(*q++);
  getchar();
  getchar();
  char *text = "abcd";
  char *p = text;
  p += strlen(p) - 1;
  while (text <= p)
    puts(p--);
  flushall();
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     118c <main+0x3c>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <putchar@plt>
jmp    1163 <main+0x13>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
lea    0xe5f(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <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     11f2 <main+0xa2>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
mov    %eax,%edi
call   1040 <puts@plt>
jmp    11c9 <main+0x79>
mov    $0x0,%al
call   1060 <flushall@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x61,%edi
call   1030 <putchar@plt>
mov    $0x62,%edi
call   1030 <putchar@plt>
mov    $0x63,%edi
call   1030 <putchar@plt>
mov    $0x64,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xe6f(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11c3 <main+0x73>
lea    -0x1(%rax),%ebx
add    %r14,%rbx
lea    (%rax,%r14,1),%ebp
add    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
mov    %ebp,%edi
call   1040 <puts@plt>
add    $0xffffffff,%ebp
cmp    %r14,%rbx
jae    11b0 <main+0x60>
xor    %eax,%eax
call   1060 <flushall@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <getchar@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"abcd\00"
define void @main() {
%1 = tail call i32 @putchar(i32 97)
%2 = tail call i32 @putchar(i32 98)
%3 = tail call i32 @putchar(i32 99)
%4 = tail call i32 @putchar(i32 100)
%5 = tail call i32 (...) @getchar()
%6 = tail call i32 (...) @getchar()
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp slt i32 %7, 1
br i1 %8, label %20, label %9
9: ; preds = %0
%10 = add nsw i32 %7, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [5 x i8], [5 x i8]* @.str, i64 0, i64 %11
br label %13
13: ; preds = %9, %13
%14 = phi i8* [ %15, %13 ], [ %12, %9 ]
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = ptrtoint i8* %14 to i64
%17 = trunc i64 %16 to i32
%18 = tail call i32 @puts(i32 %17)
%19 = icmp ult i8* %15, getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
br i1 %19, label %20, label %13
20: ; preds = %13, %0
%21 = tail call i32 (...) @flushall()
%22 = tail call i32 (...) @getchar()
ret void
}