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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned char);
unsigned char recover_byte(int /*<<< orphan*/ *);
int recover(FILE *input_fp, FILE *output_fp) {
  long output_size = 0;
  char *line = NULL;
  unsigned char byte = 0;
  int b = 0;
  if (input_fp == NULL) {
    return 1;
  }
  byte = recover_byte(input_fp);
  b = 0;
  output_size = 0;
  while (b < sizeof(output_size) && !feof(input_fp)) {
    output_size = output_size << 8 | byte;
    byte = recover_byte(input_fp);
    b++;
  }
  while (output_size-- > 0 && !feof(input_fp)) {
    fprintf(output_fp, "%c", byte);
    byte = recover_byte(input_fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<recover>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <recover+0x42>
movl   $0x1,-0x4(%rbp)
jmp    1264 <recover+0x134>
mov    -0x10(%rbp),%rdi
call   1030 <recover_byte@plt>
mov    %al,-0x29(%rbp)
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
movslq -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    $0x8,%rcx
mov    %al,-0x31(%rbp)
jae    11b4 <recover+0x84>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11c4 <recover+0x94>
jmp    11f1 <recover+0xc1>
mov    -0x20(%rbp),%rax
shl    $0x8,%rax
movzbl -0x29(%rbp),%ecx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <recover_byte@plt>
mov    %al,-0x29(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118d <recover+0x5d>
jmp    11f6 <recover+0xc6>
mov    -0x20(%rbp),%rcx
mov    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x32(%rbp)
jle    1228 <recover+0xf8>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    1238 <recover+0x108>
jmp    125d <recover+0x12d>
mov    -0x18(%rbp),%rdi
lea    0xdbd(%rip),%rsi
movzbl -0x29(%rbp),%edx
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <recover_byte@plt>
mov    %al,-0x29(%rbp)
jmp    11f6 <recover+0xc6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recover>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     12ad <recover+0x17d>
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
xor    %r14d,%r14d
test   %eax,%eax
jne    12b3 <recover+0x183>
movzbl %bl,%ebp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
mov    %rbp,%rax
shl    $0x8,%rax
movzbl %bl,%ebp
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
mov    %rbp,%rax
shl    $0x8,%rax
movzbl %bl,%ebp
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
mov    %rbp,%rax
shl    $0x8,%rax
movzbl %bl,%ebp
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
mov    %rbp,%rax
shl    $0x8,%rax
movzbl %bl,%ebp
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
mov    %rbp,%rax
shl    $0x8,%rax
movzbl %bl,%ebp
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
mov    %rbp,%rax
shl    $0x8,%rax
movzbl %bl,%ebp
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    126c <recover+0x13c>
shl    $0x8,%rbp
movzbl %bl,%eax
or     %rax,%rbp
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
test   %rbp,%rbp
jle    12b3 <recover+0x183>
add    $0x1,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    12b3 <recover+0x183>
movsbl %bl,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
mov    %r12,%rdi
call   1040 <recover_byte@plt>
mov    %eax,%ebx
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
jg     1280 <recover+0x150>
jmp    12b3 <recover+0x183>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i32 @recover(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 0, i64* %6
store i8* null, i8** %7
store i8 0, i8* %8
store i32 0, i32* %9
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %56
13: ; preds = %2
%14 = load i32*, i32** %4
%15 = call zeroext i8 @recover_byte(i32* %14)
store i8 %15, i8* %8
store i32 0, i32* %9
store i64 0, i64* %6
br label %16
16: ; preds = %27, %13
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %18, 8
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32*, i32** %4
%22 = call i32 @feof(i32* %21)
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br label %25
25: ; preds = %20, %16
%26 = phi i1 [ false, %16 ], [ %24, %20 ]
br i1 %26, label %27, label %37
27: ; preds = %25
%28 = load i64, i64* %6
%29 = shl i64 %28, 8
%30 = load i8, i8* %8
%31 = zext i8 %30 to i64
%32 = or i64 %29, %31
store i64 %32, i64* %6
%33 = load i32*, i32** %4
%34 = call zeroext i8 @recover_byte(i32* %33)
store i8 %34, i8* %8
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %16
37: ; preds = %25
br label %38
38: ; preds = %49, %37
%39 = load i64, i64* %6
%40 = add nsw i64 %39, -1
store i64 %40, i64* %6
%41 = icmp sgt i64 %39, 0
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i32*, i32** %4
%44 = call i32 @feof(i32* %43)
%45 = icmp ne i32 %44, 0
%46 = xor i1 %45, true
br label %47
47: ; preds = %42, %38
%48 = phi i1 [ false, %38 ], [ %46, %42 ]
br i1 %48, label %49, label %55
49: ; preds = %47
%50 = load i32*, i32** %5
%51 = load i8, i8* %8
%52 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %51)
%53 = load i32*, i32** %4
%54 = call zeroext i8 @recover_byte(i32* %53)
store i8 %54, i8* %8
br label %38
55: ; preds = %47
store i32 0, i32* %3
br label %56
56: ; preds = %55, %12
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
define i32 @recover(i32* %0, i32* nocapture %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %75, label %4
4: ; preds = %2
%5 = tail call zeroext i8 @recover_byte(i32* %0)
%6 = tail call i32 @feof(i32* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %75
8: ; preds = %4
%9 = zext i8 %5 to i64
%10 = tail call zeroext i8 @recover_byte(i32* %0)
%11 = tail call i32 @feof(i32* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %60
13: ; preds = %8
%14 = shl nuw nsw i64 %9, 8
%15 = zext i8 %10 to i64
%16 = or i64 %14, %15
%17 = tail call zeroext i8 @recover_byte(i32* %0)
%18 = tail call i32 @feof(i32* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %60
20: ; preds = %13
%21 = shl nuw nsw i64 %16, 8
%22 = zext i8 %17 to i64
%23 = or i64 %21, %22
%24 = tail call zeroext i8 @recover_byte(i32* %0)
%25 = tail call i32 @feof(i32* %0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %60
27: ; preds = %20
%28 = shl nuw nsw i64 %23, 8
%29 = zext i8 %24 to i64
%30 = or i64 %28, %29
%31 = tail call zeroext i8 @recover_byte(i32* %0)
%32 = tail call i32 @feof(i32* %0)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %60
34: ; preds = %27
%35 = shl i64 %30, 8
%36 = zext i8 %31 to i64
%37 = or i64 %35, %36
%38 = tail call zeroext i8 @recover_byte(i32* %0)
%39 = tail call i32 @feof(i32* %0)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %60
41: ; preds = %34
%42 = shl i64 %37, 8
%43 = zext i8 %38 to i64
%44 = or i64 %42, %43
%45 = tail call zeroext i8 @recover_byte(i32* %0)
%46 = tail call i32 @feof(i32* %0)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %41
%49 = shl i64 %44, 8
%50 = zext i8 %45 to i64
%51 = or i64 %49, %50
%52 = tail call zeroext i8 @recover_byte(i32* %0)
%53 = tail call i32 @feof(i32* %0)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %48
%56 = shl i64 %51, 8
%57 = zext i8 %52 to i64
%58 = or i64 %56, %57
%59 = tail call zeroext i8 @recover_byte(i32* %0)
br label %60
60: ; preds = %55, %48, %41, %34, %27, %20, %13, %8
%61 = phi i64 [ %9, %8 ], [ %16, %13 ], [ %23, %20 ], [ %30, %27 ], [ %37, %34 ], [ %44, %41 ], [ %51, %48 ], [ %58, %55 ]
%62 = phi i8 [ %10, %8 ], [ %17, %13 ], [ %24, %20 ], [ %31, %27 ], [ %38, %34 ], [ %45, %41 ], [ %52, %48 ], [ %59, %55 ]
%63 = icmp sgt i64 %61, 0
br i1 %63, label %64, label %75
64: ; preds = %60, %69
%65 = phi i64 [ %70, %69 ], [ %61, %60 ]
%66 = phi i8 [ %73, %69 ], [ %62, %60 ]
%67 = tail call i32 @feof(i32* %0)
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %75
69: ; preds = %64
%70 = add nsw i64 %65, -1
%71 = sext i8 %66 to i32
%72 = tail call i32 @fputc(i32 %71, i32* %1)
%73 = tail call zeroext i8 @recover_byte(i32* %0)
%74 = icmp sgt i64 %65, 1
br i1 %74, label %64, label %75
75: ; preds = %69, %64, %4, %60, %2
%76 = phi i32 [ 1, %2 ], [ 0, %60 ], [ 0, %4 ], [ 0, %64 ], [ 0, %69 ]
ret i32 %76
}