#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  register char *t, *bp;
  char buf[BUFSIZ];
  bp = buf;
  do {
    if (argc > 1 && !freopen(*++argv, "r", stdin)) {
      fprintf(stderr, "rev: cannot open %s.\n", *argv);
      exit(1);
    }
    while (fgets(bp, sizeof(buf), stdin)) {
      for (t = bp; *t; ++t)
        ;
      if (*--t == '\n')
        --t;
      for (; t >= bp; --t)
        putchar(*t);
      putchar('\n');
    }
  } while (--argc > 1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,%rsp
mov    %rcx,-0x30(%rbp)
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11f9 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    0xe3b(%rip),%rsi
call   1040 <freopen@plt>
cmp    $0x0,%eax
jne    11f9 <main+0xa9>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe18(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11fe <main+0xae>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12b2 <main+0x162>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     124b <main+0xfb>
jmp    123a <main+0xea>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1228 <main+0xd8>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0xa,%eax
jne    1273 <main+0x123>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1278 <main+0x128>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     12a3 <main+0x153>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1278 <main+0x128>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11fe <main+0xae>
jmp    12b7 <main+0x167>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x1,%eax
jg     1198 <main+0x48>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,-0x30(%rbp)
mov    %edi,%r15d
mov    0x2e64(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2e5e(%rip),%r13
jmp    11a1 <main+0x51>
nopl   0x0(%rax)
lea    -0x1(%r15),%eax
cmp    $0x2,%r15d
mov    %eax,%r15d
jle    1254 <main+0x104>
cmp    $0x2,%r15d
jl     11cf <main+0x7f>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    0x0(%r13),%edx
lea    0xe3e(%rip),%rsi
call   1040 <freopen@plt>
test   %eax,%eax
je     125b <main+0x10b>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1190 <main+0x40>
mov    %rbx,%rcx
jmp    1215 <main+0xc5>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <fgets@plt>
mov    %rbx,%rcx
test   %rax,%rax
je     1190 <main+0x40>
mov    %rcx,%rax
add    $0x1,%rcx
cmpb   $0x0,(%rax)
jne    1215 <main+0xc5>
lea    -0x1(%rax),%r14
cmpb   $0xa,-0x1(%rax)
lea    -0x2(%rax),%rax
cmove  %rax,%r14
cmp    %rbx,%r14
jb     11f0 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%r14
cmp    %rbx,%r14
jae    1240 <main+0xf0>
jmp    11f0 <main+0xa0>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
lea    0xd90(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"rev: cannot open %s.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
store i8* %13, i8** %7
br label %14
14: ; preds = %71, %2
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8*, i8** %19
%21 = load i32, i32* @stdin
%22 = call i32 @freopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17, %14
br label %31
31: ; preds = %68, %30
%32 = load i8*, i8** %7
%33 = trunc i64 %11 to i32
%34 = load i32, i32* @stdin
%35 = call i64 @fgets(i8* %32, i32 %33, i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %70
37: ; preds = %31
%38 = load i8*, i8** %7
store i8* %38, i8** %6
br label %39
39: ; preds = %44, %37
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = icmp ne i8 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
br label %44
44: ; preds = %43
%45 = load i8*, i8** %6
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %6
br label %39
47: ; preds = %39
%48 = load i8*, i8** %6
%49 = getelementptr inbounds i8, i8* %48, i32 -1
store i8* %49, i8** %6
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i8*, i8** %6
%55 = getelementptr inbounds i8, i8* %54, i32 -1
store i8* %55, i8** %6
br label %56
56: ; preds = %53, %47
br label %57
57: ; preds = %65, %56
%58 = load i8*, i8** %6
%59 = load i8*, i8** %7
%60 = icmp uge i8* %58, %59
br i1 %60, label %61, label %68
61: ; preds = %57
%62 = load i8*, i8** %6
%63 = load i8, i8* %62
%64 = call i32 @putchar(i8 signext %63)
br label %65
65: ; preds = %61
%66 = load i8*, i8** %6
%67 = getelementptr inbounds i8, i8* %66, i32 -1
store i8* %67, i8** %6
br label %57
68: ; preds = %57
%69 = call i32 @putchar(i8 signext 10)
br label %31
70: ; preds = %31
br label %71
71: ; preds = %70
%72 = load i32, i32* %4
%73 = add nsw i32 %72, -1
store i32 %73, i32* %4
%74 = icmp sgt i32 %73, 1
br i1 %74, label %14, label %75
75: ; preds = %71
%76 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"rev: cannot open %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
br label %6
6: ; preds = %51, %2
%7 = phi i8** [ %1, %2 ], [ %22, %51 ]
%8 = phi i32 [ %0, %2 ], [ %52, %51 ]
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = getelementptr inbounds i8*, i8** %7, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @stdin
%14 = call i32 @freopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %11
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %10, %6
%22 = phi i8** [ %11, %10 ], [ %7, %6 ]
%23 = load i32, i32* @stdin
%24 = call i64 @fgets(i8* %5, i32 %3, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %51, label %26
26: ; preds = %21, %31
%27 = phi i8* [ %32, %31 ], [ %5, %21 ]
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
%30 = getelementptr inbounds i8, i8* %27, i64 1
br i1 %29, label %33, label %31
31: ; preds = %26, %46
%32 = phi i8* [ %30, %26 ], [ %5, %46 ]
br label %26
33: ; preds = %26
%34 = getelementptr inbounds i8, i8* %27, i64 -1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 10
%37 = getelementptr inbounds i8, i8* %27, i64 -2
%38 = select i1 %36, i8* %37, i8* %34
%39 = icmp ult i8* %38, %5
br i1 %39, label %46, label %40
40: ; preds = %33, %40
%41 = phi i8* [ %44, %40 ], [ %38, %33 ]
%42 = load i8, i8* %41
%43 = call i32 @putchar(i8 signext %42)
%44 = getelementptr inbounds i8, i8* %41, i64 -1
%45 = icmp ult i8* %44, %5
br i1 %45, label %46, label %40
46: ; preds = %40, %33
%47 = call i32 @putchar(i8 signext 10)
%48 = load i32, i32* @stdin
%49 = call i64 @fgets(i8* %5, i32 %3, i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %31
51: ; preds = %46, %21
%52 = add nsw i32 %8, -1
%53 = icmp sgt i32 %8, 2
br i1 %53, label %6, label %54
54: ; preds = %51
%55 = call i32 @exit(i32 0)
unreachable
}