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

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *stdin;
size_t strlen(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  const char *filename;
  char p[2000], *t;
  FILE *fp;
  size_t len;
  int ch, rval;
  setlocale(LC_ALL, "");
  while ((ch = getopt(argc, argv, "")) != -1)
    switch (ch) {
    case '?':
    default:
      usage();
    }
  argc -= optind;
  argv += optind;
  fp = stdin;
  filename = "stdin";
  rval = 0;
  do {
    if (*argv) {
      if ((fp = fopen(*argv, "r")) == NULL) {
        perror(*argv);
        rval = 1;
        ++argv;
        continue;
      }
      filename = *argv++;
    }
    while ((fgets(p, sizeof(p) - 1, fp)) != NULL) {
      len = strlen(p);
      if (p[len - 1] == '\n')
        --len;
      t = p + len - 1;
      for (t = p + len - 1; t >= p; --t)
        putchar(*t);
      putchar('\n');
    }
    if (ferror(fp)) {
      perror(filename);
      rval = 1;
    }
    (void)fclose(fp);
  } while (*argv);
  exit(rval);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1080 <setlocale@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe19(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x80c(%rbp)
cmp    $0xffffffff,%eax
je     1225 <main+0x75>
mov    -0x80c(%rbp),%eax
sub    $0x3f,%eax
jne    1219 <main+0x69>
jmp    1214 <main+0x64>
jmp    1219 <main+0x69>
mov    $0x0,%al
call   1090 <usage@plt>
jmp    11de <main+0x2e>
mov    0x2db4(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x800(%rbp)
lea    0xd99(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x810(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e4 <main+0x134>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd75(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x800(%rbp)
cmp    $0x0,%rax
jne    12ce <main+0x11e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x810(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    13ff <main+0x24f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12e9 <main+0x139>
lea    -0x7f0(%rbp),%rdi
mov    -0x800(%rbp),%rdx
mov    $0x7cf,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     13ca <main+0x21a>
lea    -0x7f0(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x808(%rbp)
mov    -0x808(%rbp),%rax
sub    $0x1,%rax
movsbl -0x7f0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    134c <main+0x19c>
mov    -0x808(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x808(%rbp)
lea    -0x7f0(%rbp),%rax
add    -0x808(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x7f8(%rbp)
lea    -0x7f0(%rbp),%rax
add    -0x808(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x7f8(%rbp)
mov    -0x7f8(%rbp),%rax
lea    -0x7f0(%rbp),%rcx
cmp    %rcx,%rax
jb     13bb <main+0x20b>
mov    -0x7f8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x7f8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x7f8(%rbp)
jmp    137e <main+0x1ce>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12e9 <main+0x139>
mov    -0x800(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     13f3 <main+0x243>
mov    -0x18(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x810(%rbp)
mov    -0x800(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1275 <main+0xc5>
mov    -0x810(%rbp),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7e8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%r14
mov    %r14,%rsi
call   1080 <setlocale@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10c0 <getopt@plt>
cmp    $0xffffffff,%eax
je     1219 <main+0x69>
lea    0xe0e(%rip),%r14
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10c0 <getopt@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0x50>
mov    0x2dc0(%rip),%rax
mov    (%rax),%rax
lea    (%rbx,%rax,8),%rbp
mov    0x2dba(%rip),%rcx
mov    (%rcx),%r13
mov    (%rbx,%rax,8),%rdi
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    0xdbd(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xdb7(%rip),%r15
jmp    1286 <main+0xd6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1315 <main+0x165>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
je     134b <main+0x19b>
test   %rdi,%rdi
je     12ba <main+0x10a>
mov    %r15,%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     132c <main+0x17c>
mov    %rax,%r13
mov    0x0(%rbp),%r14
add    $0x8,%rbp
jmp    12ba <main+0x10a>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    $0x7cf,%esi
mov    %r13,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1260 <main+0xb0>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    -0x1(%rax),%rcx
cmpb   $0xa,0xf(%rsp,%rax,1)
cmovne %rax,%rcx
lea    (%rsp,%rcx,1),%r12
add    $0xf,%r12
cmp    %rbx,%r12
jb     12b0 <main+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r12),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%r12
cmp    %rbx,%r12
jae    1300 <main+0x150>
jmp    12b0 <main+0x100>
mov    %r14,%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
jmp    1271 <main+0xc1>
mov    0x0(%rbp),%rdi
call   10b0 <perror@plt>
add    $0x8,%rbp
mov    $0x1,%eax
mov    %rax,0x8(%rsp)
xor    %r13d,%r13d
jmp    1279 <main+0xc9>
mov    0x8(%rsp),%rdi
call   10d0 <exit@plt>

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@stdin = global i32* null
@.str.1 = [6 x i8] c"stdin\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [2000 x i8]
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @LC_ALL
%14 = call i32 @setlocale(i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %11
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load i32, i32* %11
switch i32 %21, label %23 [
i32 63, label %22
]
22: ; preds = %20
br label %23
23: ; preds = %20, %22
%24 = call i32 (...) @usage()
br label %25
25: ; preds = %23
br label %15
26: ; preds = %15
%27 = load i64, i64* @optind
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = sub nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %4
%32 = load i64, i64* @optind
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 %32
store i8** %34, i8*** %5
%35 = load i32*, i32** @stdin
store i32* %35, i32** %9
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i32 0, i32* %12
br label %36
36: ; preds = %105, %26
%37 = load i8**, i8*** %5
%38 = load i8*, i8** %37
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %43, i32** %9
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i8**, i8*** %5
%47 = load i8*, i8** %46
%48 = call i32 @perror(i8* %47)
store i32 1, i32* %12
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i32 1
store i8** %50, i8*** %5
br label %105
51: ; preds = %40
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i32 1
store i8** %53, i8*** %5
%54 = load i8*, i8** %52
store i8* %54, i8** %6
br label %55
55: ; preds = %51, %36
br label %56
56: ; preds = %93, %55
%57 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%58 = load i32*, i32** %9
%59 = call i32* @fgets(i8* %57, i32 1999, i32* %58)
%60 = icmp ne i32* %59, null
br i1 %60, label %61, label %95
61: ; preds = %56
%62 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%63 = call i64 @strlen(i8* %62)
store i64 %63, i64* %10
%64 = load i64, i64* %10
%65 = sub i64 %64, 1
%66 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 10
br i1 %69, label %70, label %73
70: ; preds = %61
%71 = load i64, i64* %10
%72 = add i64 %71, -1
store i64 %72, i64* %10
br label %73
73: ; preds = %70, %61
%74 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%75 = load i64, i64* %10
%76 = getelementptr inbounds i8, i8* %74, i64 %75
%77 = getelementptr inbounds i8, i8* %76, i64 -1
store i8* %77, i8** %8
%78 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%79 = load i64, i64* %10
%80 = getelementptr inbounds i8, i8* %78, i64 %79
%81 = getelementptr inbounds i8, i8* %80, i64 -1
store i8* %81, i8** %8
br label %82
82: ; preds = %90, %73
%83 = load i8*, i8** %8
%84 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%85 = icmp uge i8* %83, %84
br i1 %85, label %86, label %93
86: ; preds = %82
%87 = load i8*, i8** %8
%88 = load i8, i8* %87
%89 = call i32 @putchar(i8 signext %88)
br label %90
90: ; preds = %86
%91 = load i8*, i8** %8
%92 = getelementptr inbounds i8, i8* %91, i32 -1
store i8* %92, i8** %8
br label %82
93: ; preds = %82
%94 = call i32 @putchar(i8 signext 10)
br label %56
95: ; preds = %56
%96 = load i32*, i32** %9
%97 = call i64 @ferror(i32* %96)
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %102
99: ; preds = %95
%100 = load i8*, i8** %6
%101 = call i32 @perror(i8* %100)
store i32 1, i32* %12
br label %102
102: ; preds = %99, %95
%103 = load i32*, i32** %9
%104 = call i32 @fclose(i32* %103)
br label %105
105: ; preds = %102, %45
%106 = load i8**, i8*** %5
%107 = load i8*, i8** %106
%108 = icmp ne i8* %107, null
br i1 %108, label %36, label %109
109: ; preds = %105
%110 = load i32, i32* %12
%111 = call i32 @exit(i32 %110)
unreachable
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@stdin = global i32* null
@.str.1 = [6 x i8] c"stdin\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2000 x i8]
%4 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LC_ALL
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %13, label %9
9: ; preds = %2, %9
%10 = tail call i32 (...) @usage()
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %9
13: ; preds = %9, %2
%14 = load i64, i64* @optind
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i32*, i32** @stdin
%17 = load i8*, i8** %15
br label %18
18: ; preds = %69, %13
%19 = phi i8* [ %74, %69 ], [ %17, %13 ]
%20 = phi i8** [ %70, %69 ], [ %15, %13 ]
%21 = phi i8* [ %71, %69 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %13 ]
%22 = phi i32* [ %72, %69 ], [ %16, %13 ]
%23 = phi i32 [ %73, %69 ], [ 0, %13 ]
%24 = icmp eq i8* %19, null
br i1 %24, label %35, label %25
25: ; preds = %18
%26 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8*, i8** %20
%30 = call i32 @perror(i8* %29)
%31 = getelementptr inbounds i8*, i8** %20, i64 1
br label %69
32: ; preds = %25
%33 = getelementptr inbounds i8*, i8** %20, i64 1
%34 = load i8*, i8** %20
br label %35
35: ; preds = %32, %18
%36 = phi i8** [ %33, %32 ], [ %20, %18 ]
%37 = phi i8* [ %34, %32 ], [ %21, %18 ]
%38 = phi i32* [ %26, %32 ], [ %22, %18 ]
%39 = call i32* @fgets(i8* %4, i32 1999, i32* %38)
%40 = icmp eq i32* %39, null
br i1 %40, label %61, label %41
41: ; preds = %35, %57
%42 = call i64 @strlen(i8* %4)
%43 = add i64 %42, -1
%44 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 10
%47 = select i1 %46, i64 %43, i64 %42
%48 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 %47
%49 = getelementptr inbounds i8, i8* %48, i64 -1
%50 = icmp ult i8* %49, %4
br i1 %50, label %57, label %51
51: ; preds = %41, %51
%52 = phi i8* [ %55, %51 ], [ %49, %41 ]
%53 = load i8, i8* %52
%54 = call i32 @putchar(i8 signext %53)
%55 = getelementptr inbounds i8, i8* %52, i64 -1
%56 = icmp ult i8* %55, %4
br i1 %56, label %57, label %51
57: ; preds = %51, %41
%58 = call i32 @putchar(i8 signext 10)
%59 = call i32* @fgets(i8* %4, i32 1999, i32* %38)
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %41
61: ; preds = %57, %35
%62 = call i64 @ferror(i32* %38)
%63 = icmp eq i64 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %61
%65 = call i32 @perror(i8* %37)
br label %66
66: ; preds = %64, %61
%67 = phi i32 [ 1, %64 ], [ %23, %61 ]
%68 = call i32 @fclose(i32* %38)
br label %69
69: ; preds = %66, %28
%70 = phi i8** [ %31, %28 ], [ %36, %66 ]
%71 = phi i8* [ %21, %28 ], [ %37, %66 ]
%72 = phi i32* [ null, %28 ], [ %38, %66 ]
%73 = phi i32 [ 1, %28 ], [ %67, %66 ]
%74 = load i8*, i8** %70
%75 = icmp eq i8* %74, null
br i1 %75, label %76, label %18
76: ; preds = %69
%77 = call i32 @exit(i32 %73)
unreachable
}