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

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int readchar_low(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int readchar(int fd) {
  int c = -1;
  for (;;) {
    c = readchar_low(fd);
    if (c == -1) {
      syslog(LOG_INFO, "Lost connection");
      break;
    }
    if (c == 255) {
      readchar_low(fd);
      readchar_low(fd);
      continue;
    }
    break;
  }
  return c;
}


x86 assembly (clang, -O0):
<readchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <readchar_low@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1161 <readchar+0x41>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1040 <syslog@plt>
jmp    1188 <readchar+0x68>
cmpl   $0xff,-0x8(%rbp)
jne    1183 <readchar+0x63>
mov    -0x4(%rbp),%edi
call   1030 <readchar_low@plt>
mov    -0x4(%rbp),%edi
call   1030 <readchar_low@plt>
jmp    1132 <readchar+0x12>
jmp    1188 <readchar+0x68>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readchar>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1030 <readchar_low@plt>
cmp    $0xff,%eax
jne    114e <readchar+0x2e>
mov    %ebp,%edi
call   1030 <readchar_low@plt>
mov    %ebp,%edi
call   1030 <readchar_low@plt>
jmp    1130 <readchar+0x10>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    116a <readchar+0x4a>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
call   1040 <syslog@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [16 x i8] c"Lost connection\00"
define i32 @readchar(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %3
br label %4
4: ; preds = %15, %1
%5 = load i32, i32* %2
%6 = call i32 @readchar_low(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @LOG_INFO
%11 = call i32 @syslog(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %21
12: ; preds = %4
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 255
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* %2
%17 = call i32 @readchar_low(i32 %16)
%18 = load i32, i32* %2
%19 = call i32 @readchar_low(i32 %18)
br label %4
20: ; preds = %12
br label %21
21: ; preds = %20, %9
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [16 x i8] c"Lost connection\00"
define i32 @readchar(i32 %0) {
br label %2
2: ; preds = %7, %1
%3 = tail call i32 @readchar_low(i32 %0)
switch i32 %3, label %10 [
i32 -1, label %4
i32 255, label %7
]
4: ; preds = %2
%5 = load i32, i32* @LOG_INFO
%6 = tail call i32 @syslog(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
7: ; preds = %2
%8 = tail call i32 @readchar_low(i32 %0)
%9 = tail call i32 @readchar_low(i32 %0)
br label %2
10: ; preds = %2, %4
ret i32 %3
}