#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 */
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int main(void) {
  int max = 0;
self:
  if (*("A man a plan a canal panama.\n" + max++))
    goto self;
  else
    max--;
  char *str = malloc(max-- + 1);
  int i = 0;
rev:
  if (max - i + 1)
    *(str + i) = *("A man a plan a canal panama.\n" + max - i++);
  else
    goto end;
  goto rev;
end:
  printf("%s", str);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
movslq %eax,%rcx
lea    0xeb5(%rip),%rax
cmpb   $0x0,(%rax,%rcx,1)
je     115a <main+0x3a>
jmp    1136 <main+0x16>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    %edi,%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    $0x0,%eax
je     11c7 <main+0xa7>
movslq -0x8(%rbp),%rcx
lea    0xe62(%rip),%rax
add    %rcx,%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11cc <main+0xac>
jmp    11d1 <main+0xb1>
jmp    1181 <main+0x61>
mov    -0x10(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x1e,%edi
call   1040 <malloc@plt>
movaps 0xece(%rip),%xmm0
movups %xmm0,0x1(%rax)
movabs $0x206120706c616e20,%rcx
20 61 20
mov    %rcx,0x11(%rax)
movl   $0x206d616e,0x19(%rax)
movb   $0x41,0x1d(%rax)
lea    0xeba(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"A man a plan a canal panama.\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %12, %0
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
store i32 %7, i32* %2
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds i8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %8
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %5
br label %5
13: ; preds = %5
%14 = load i32, i32* %2
%15 = add nsw i32 %14, -1
store i32 %15, i32* %2
br label %16
16: ; preds = %13
%17 = load i32, i32* %2
%18 = add nsw i32 %17, -1
store i32 %18, i32* %2
%19 = add nsw i32 %17, 1
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %3
store i32 0, i32* %4
br label %21
21: ; preds = %42, %16
%22 = load i32, i32* %2
%23 = load i32, i32* %4
%24 = sub nsw i32 %22, %23
%25 = add nsw i32 %24, 1
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %21
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = sext i32 %31 to i64
%34 = sub i64 0, %33
%35 = getelementptr inbounds i8, i8* %30, i64 %34
%36 = load i8, i8* %35
%37 = load i8*, i8** %3
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
br label %42
41: ; preds = %21
br label %43
42: ; preds = %27
br label %21
43: ; preds = %41
%44 = load i8*, i8** %3
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(30) i8* @malloc(i32 30)
%2 = getelementptr inbounds i8, i8* %1, i64 1
%3 = bitcast i8* %2 to <16 x i8>*
store <16 x i8> <i8 10, i8 46, i8 97, i8 109, i8 97, i8 110, i8 97, i8 112, i8 32, i8 108, i8 97, i8 110, i8 97, i8 99, i8 32, i8 97>, <16 x i8>* %3
%4 = getelementptr inbounds i8, i8* %1, i64 17
store i8 32, i8* %4
%5 = getelementptr inbounds i8, i8* %1, i64 18
store i8 110, i8* %5
%6 = getelementptr inbounds i8, i8* %1, i64 19
store i8 97, i8* %6
%7 = getelementptr inbounds i8, i8* %1, i64 20
store i8 108, i8* %7
%8 = getelementptr inbounds i8, i8* %1, i64 21
store i8 112, i8* %8
%9 = getelementptr inbounds i8, i8* %1, i64 22
store i8 32, i8* %9
%10 = getelementptr inbounds i8, i8* %1, i64 23
store i8 97, i8* %10
%11 = getelementptr inbounds i8, i8* %1, i64 24
store i8 32, i8* %11
%12 = getelementptr inbounds i8, i8* %1, i64 25
store i8 110, i8* %12
%13 = getelementptr inbounds i8, i8* %1, i64 26
store i8 97, i8* %13
%14 = getelementptr inbounds i8, i8* %1, i64 27
store i8 109, i8* %14
%15 = getelementptr inbounds i8, i8* %1, i64 28
store i8 32, i8* %15
%16 = getelementptr inbounds i8, i8* %1, i64 29
store i8 65, i8* %16
%17 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
ret i32 0
}