#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 EOF;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ flockfile(int /*<<< orphan*/);
int /*<<< orphan*/ funlockfile(int /*<<< orphan*/);
int putchar_unlocked(char);
int /*<<< orphan*/ stdout;
void dump_output_reverse(char *str, char *str_end) {
  int ret;
  char tmp;
  str--;
  flockfile(stdout);
  for (str_end--; str_end != str; str_end--) {
    tmp = *str_end;
    ret = putchar_unlocked(tmp);
    if (ret == EOF)
      die("could not write to standard output");
  }
  funlockfile(stdout);
}


x86 assembly (clang, -O0):
<dump_output_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1040 <flockfile@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11cd <dump_output_reverse+0x8d>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <putchar_unlocked@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e45(%rip),%rcx
cmp    (%rcx),%eax
jne    11b7 <dump_output_reverse+0x77>
lea    0xe4e(%rip),%rdi
call   1060 <die@plt>
jmp    11bc <dump_output_reverse+0x7c>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1176 <dump_output_reverse+0x36>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1030 <funlockfile@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_output_reverse>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e82(%rip),%r12
mov    (%r12),%edi
call   1040 <flockfile@plt>
cmp    %r14,%rbx
je     11a2 <dump_output_reverse+0x62>
mov    0x2e7d(%rip),%r13
lea    0xe8e(%rip),%r15
jmp    1185 <dump_output_reverse+0x45>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r14,%rbx
je     11a2 <dump_output_reverse+0x62>
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1050 <putchar_unlocked@plt>
cmp    0x0(%r13),%eax
jne    1180 <dump_output_reverse+0x40>
mov    %r15,%rdi
call   1060 <die@plt>
jmp    1180 <dump_output_reverse+0x40>
mov    (%r12),%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <funlockfile@plt>

LLVM IR (-O0):
@stdout = global i32 0
@EOF = global i32 0
@.str = [35 x i8] c"could not write to standard output\00"
define void @dump_output_reverse(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i32 -1
store i8* %8, i8** %3
%9 = load i32, i32* @stdout
%10 = call i32 @flockfile(i32 %9)
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 -1
store i8* %12, i8** %4
br label %13
13: ; preds = %28, %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %3
%16 = icmp ne i8* %14, %15
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
store i8 %19, i8* %6
%20 = load i8, i8* %6
%21 = call i32 @putchar_unlocked(i8 signext %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %17
br label %28
28: ; preds = %27
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %4
br label %13
31: ; preds = %13
%32 = load i32, i32* @stdout
%33 = call i32 @funlockfile(i32 %32)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@EOF = global i32 0
@.str = [35 x i8] c"could not write to standard output\00"
define void @dump_output_reverse(i8* readnone %0, i8* %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @flockfile(i32 %3)
%5 = icmp eq i8* %1, %0
br i1 %5, label %17, label %6
6: ; preds = %2, %15
%7 = phi i8* [ %8, %15 ], [ %1, %2 ]
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = load i8, i8* %8
%10 = tail call i32 @putchar_unlocked(i8 signext %9)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @die(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %6, %13
%16 = icmp eq i8* %8, %0
br i1 %16, label %17, label %6
17: ; preds = %15, %2
%18 = load i32, i32* @stdout
%19 = tail call i32 @funlockfile(i32 %18)
ret void
}