#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*/ FILE;

/* Variables and functions */
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int readaline_and_out(FILE *fin, FILE *fout) {
  int ch, count = 0;
  int arr[200], i = 0;
  do {
    if ((ch = fgetc(fin)) == EOF) {
      if (!count)
        return 1;
      else {
        fputc(0x0a, fout);
        break;
      }
    }
    arr[count] = ch;
    count++;
  } while (ch != 0x0a);
  for (i = count - 1; i > 0; i--) {
    fputc(arr[i - 1], fout);
  }
  fputc('\n', fout);
  return 0;
}


x86 assembly (clang, -O0):
<readaline_and_out>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x344(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e91(%rip),%rcx
cmp    (%rcx),%eax
jne    1188 <readaline_and_out+0x68>
cmpl   $0x0,-0x20(%rbp)
jne    1175 <readaline_and_out+0x55>
movl   $0x1,-0x4(%rbp)
jmp    1209 <readaline_and_out+0xe9>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
jmp    11a9 <readaline_and_out+0x89>
mov    -0x1c(%rbp),%ecx
movslq -0x20(%rbp),%rax
mov    %ecx,-0x340(%rbp,%rax,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jne    1144 <readaline_and_out+0x24>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x344(%rbp)
cmpl   $0x0,-0x344(%rbp)
jle    11f4 <readaline_and_out+0xd4>
mov    -0x344(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x340(%rbp,%rax,4),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x344(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x344(%rbp)
jmp    11b5 <readaline_and_out+0x95>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readaline_and_out>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x328,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2eab(%rip),%r12
nopl   (%rax)
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     1161 <readaline_and_out+0x41>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xa,%eax
jne    1140 <readaline_and_out+0x20>
cmp    $0x2,%ebx
jge    1177 <readaline_and_out+0x57>
jmp    11ac <readaline_and_out+0x8c>
test   %ebx,%ebx
je     11bd <readaline_and_out+0x9d>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
cmp    $0x2,%ebx
jl     11ac <readaline_and_out+0x8c>
mov    %ebx,%r15d
mov    $0xfffffffe,%ebx
add    %r15,%rbx
add    $0x1,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
movsbl (%rsp,%rax,4),%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%r15
cmp    $0x2,%r15
ja     1190 <readaline_and_out+0x70>
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
xor    %eax,%eax
jmp    11c2 <readaline_and_out+0xa2>
mov    $0x1,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @readaline_and_out(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [200 x i32]
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %29, %2
%11 = load i32*, i32** %4
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %6
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %15
store i32 1, i32* %3
br label %53
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i32 @fputc(i8 signext 10, i32* %20)
br label %32
22: ; preds = %10
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [200 x i32], [200 x i32]* %8, i64 0, i64 %25
store i32 %23, i32* %26
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %22
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 10
br i1 %31, label %10, label %32
32: ; preds = %29, %19
%33 = load i32, i32* %7
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %9
br label %35
35: ; preds = %47, %32
%36 = load i32, i32* %9
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %50
38: ; preds = %35
%39 = load i32, i32* %9
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [200 x i32], [200 x i32]* %8, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = trunc i32 %43 to i8
%45 = load i32*, i32** %5
%46 = call i32 @fputc(i8 signext %44, i32* %45)
br label %47
47: ; preds = %38
%48 = load i32, i32* %9
%49 = add nsw i32 %48, -1
store i32 %49, i32* %9
br label %35
50: ; preds = %35
%51 = load i32*, i32** %5
%52 = call i32 @fputc(i8 signext 10, i32* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %50, %18
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @readaline_and_out(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [200 x i32]
%4 = bitcast [200 x i32]* %3 to i8*
br label %5
5: ; preds = %15, %2
%6 = phi i64 [ %17, %15 ], [ 0, %2 ]
%7 = tail call i32 @fgetc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = trunc i64 %6 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %38, label %13
13: ; preds = %10
%14 = tail call i32 @fputc(i8 signext 10, i32* %1)
br label %21
15: ; preds = %5
%16 = getelementptr inbounds [200 x i32], [200 x i32]* %3, i64 0, i64 %6
store i32 %7, i32* %16
%17 = add nuw i64 %6, 1
%18 = icmp eq i32 %7, 10
br i1 %18, label %19, label %5
19: ; preds = %15
%20 = trunc i64 %17 to i32
br label %21
21: ; preds = %19, %13
%22 = phi i32 [ %11, %13 ], [ %20, %19 ]
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = zext i32 %22 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ %25, %24 ], [ %28, %26 ]
%28 = add nsw i64 %27, -1
%29 = add nuw i64 %27, 4294967294
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [200 x i32], [200 x i32]* %3, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = trunc i32 %32 to i8
%34 = tail call i32 @fputc(i8 signext %33, i32* %1)
%35 = icmp ugt i64 %27, 2
br i1 %35, label %26, label %36
36: ; preds = %26, %21
%37 = tail call i32 @fputc(i8 signext 10, i32* %1)
br label %38
38: ; preds = %10, %36
%39 = phi i32 [ 0, %36 ], [ 1, %10 ]
ret i32 %39
}