#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
void readin(int fd, short *p, int bs) {
  int r;
  do {
    r = read(fd, (char *)p, 2 * bs);
  } while (r == -1 && errno == EINTR);
  if (r == -1 || r != 2 * bs) {
    perror("Input error");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<readin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jne    1180 <readin+0x50>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1142 <readin+0x12>
cmpl   $0xffffffff,-0x18(%rbp)
je     11a6 <readin+0x76>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
je     11bc <readin+0x8c>
lea    0xe53(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
add    %edx,%r14d
mov    0x2e96(%rip),%r15
mov    0x2e87(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
jne    117b <readin+0x4b>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1160 <readin+0x30>
cmp    $0xffffffff,%eax
je     118e <readin+0x5e>
cmp    %r14d,%eax
jne    118e <readin+0x5e>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [12 x i8] c"Input error\00"
define void @readin(i32 %0, i16* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i16*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i16* %1, i16** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %22, %3
%9 = load i32, i32* %4
%10 = load i16*, i16** %5
%11 = bitcast i16* %10 to i8*
%12 = load i32, i32* %6
%13 = mul nsw i32 2, %12
%14 = call i32 @read(i32 %9, i8* %11, i32 %13)
store i32 %14, i32* %7
br label %15
15: ; preds = %8
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br label %22
22: ; preds = %18, %15
%23 = phi i1 [ false, %15 ], [ %21, %18 ]
br i1 %23, label %8, label %24
24: ; preds = %22
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = load i32, i32* %6
%30 = mul nsw i32 2, %29
%31 = icmp ne i32 %28, %30
br i1 %31, label %32, label %35
32: ; preds = %27, %24
%33 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [12 x i8] c"Input error\00"
define void @readin(i32 %0, i16* nocapture %1, i32 %2) {
%4 = bitcast i16* %1 to i8*
%5 = shl nsw i32 %2, 1
br label %6
6: ; preds = %6, %3
%7 = tail call i32 @read(i32 %0, i8* %4, i32 %5)
%8 = icmp eq i32 %7, -1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
%12 = select i1 %8, i1 %11, i1 false
br i1 %12, label %6, label %13
13: ; preds = %6
%14 = icmp ne i32 %7, %5
%15 = or i1 %8, %14
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %13
ret void
}