#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 /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
unsigned char get_bit_from_blank(char);
char *get_next_line_from_file(int /*<<< orphan*/ *);
int strlen(char *);
unsigned char recover_byte(FILE *input_fp) {
  unsigned char retval = 0;
  char *line = NULL;
  int b = 0;
  line = get_next_line_from_file(input_fp);
  while (!feof(input_fp) && line != NULL && b < 8) {
    retval = retval << 1 | get_bit_from_blank(line[strlen(line) - 1]);
    b++;
    free(line);
    if (b < 8) {
      line = get_next_line_from_file(input_fp);
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<recover_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <get_next_line_from_file@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    11af <recover_byte+0x5f>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     11af <recover_byte+0x5f>
cmpl   $0x8,-0x1c(%rbp)
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11bf <recover_byte+0x6f>
jmp    122a <recover_byte+0xda>
movzbl -0x9(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <get_bit_from_blank@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
movzbl %cl,%ecx
or     %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x8,-0x1c(%rbp)
jge    1225 <recover_byte+0xd5>
mov    -0x8(%rbp),%rdi
call   1070 <get_next_line_from_file@plt>
mov    %rax,-0x18(%rbp)
jmp    117c <recover_byte+0x2c>
movzbl -0x9(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recover_byte>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1070 <get_next_line_from_file@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1060 <feof@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11d7 <recover_byte+0x87>
test   %r15,%r15
je     11d7 <recover_byte+0x87>
xor    %r12d,%r12d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%ebx
add    %bpl,%bl
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movsbl -0x1(%rax,%r15,1),%edi
call   1040 <get_bit_from_blank@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
cmp    $0x6,%r12d
ja     11b5 <recover_byte+0x65>
mov    %r14,%rdi
call   1070 <get_next_line_from_file@plt>
mov    %rax,%r15
or     %bl,%bpl
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11d7 <recover_byte+0x87>
test   %r15,%r15
je     11d7 <recover_byte+0x87>
lea    0x1(%r12),%eax
cmp    $0x7,%r12d
mov    %eax,%r12d
jb     1180 <recover_byte+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @recover_byte(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %2
store i8 0, i8* %3
store i8* null, i8** %4
store i32 0, i32* %5
%6 = load i32*, i32** %2
%7 = call i8* @get_next_line_from_file(i32* %6)
store i8* %7, i8** %4
br label %8
8: ; preds = %44, %1
%9 = load i32*, i32** %2
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 8
br label %18
18: ; preds = %15, %12, %8
%19 = phi i1 [ false, %12 ], [ false, %8 ], [ %17, %15 ]
br i1 %19, label %20, label %45
20: ; preds = %18
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 1
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = call zeroext i8 @get_bit_from_blank(i8 signext %30)
%32 = zext i8 %31 to i32
%33 = or i32 %23, %32
%34 = trunc i32 %33 to i8
store i8 %34, i8* %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 8
br i1 %40, label %41, label %44
41: ; preds = %20
%42 = load i32*, i32** %2
%43 = call i8* @get_next_line_from_file(i32* %42)
store i8* %43, i8** %4
br label %44
44: ; preds = %41, %20
br label %8
45: ; preds = %18
%46 = load i8, i8* %3
ret i8 %46
}

LLVM IR (-O2):
define zeroext i8 @recover_byte(i32* %0) {
%2 = tail call i8* @get_next_line_from_file(i32* %0)
%3 = tail call i32 @feof(i32* %0)
%4 = icmp eq i32 %3, 0
%5 = icmp ne i8* %2, null
%6 = select i1 %4, i1 %5, i1 false
br i1 %6, label %7, label %31
7: ; preds = %1, %24
%8 = phi i32 [ %19, %24 ], [ 0, %1 ]
%9 = phi i8* [ %25, %24 ], [ %2, %1 ]
%10 = phi i8 [ %18, %24 ], [ 0, %1 ]
%11 = shl i8 %10, 1
%12 = tail call i32 @strlen(i8* %9)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %9, i64 %14
%16 = load i8, i8* %15
%17 = tail call zeroext i8 @get_bit_from_blank(i8 signext %16)
%18 = or i8 %17, %11
%19 = add nuw nsw i32 %8, 1
%20 = tail call i32 @free(i8* %9)
%21 = icmp ult i32 %8, 7
br i1 %21, label %22, label %24
22: ; preds = %7
%23 = tail call i8* @get_next_line_from_file(i32* %0)
br label %24
24: ; preds = %22, %7
%25 = phi i8* [ %23, %22 ], [ %9, %7 ]
%26 = tail call i32 @feof(i32* %0)
%27 = icmp eq i32 %26, 0
%28 = icmp ne i8* %25, null
%29 = select i1 %27, i1 %28, i1 false
%30 = select i1 %29, i1 %21, i1 false
br i1 %30, label %7, label %31
31: ; preds = %24, %1
%32 = phi i8 [ 0, %1 ], [ %18, %24 ]
ret i8 %32
}