#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 read(int, char *, int);
size_t defaultReadCode(int fd, char *buf, size_t buf_len, int *c) {
  if (buf_len < 1)
    return -1;
  int nread = read(fd, &buf[0], 1);
  if (nread == 1)
    *c = buf[0];
  return nread;
}


x86 assembly (clang, -O0):
<defaultReadCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x1,-0x20(%rbp)
jae    113f <defaultReadCode+0x2f>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1172 <defaultReadCode+0x62>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    116a <defaultReadCode+0x5a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x2c(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<defaultReadCode>:
test   %rdx,%rdx
je     113e <defaultReadCode+0x2e>
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    1134 <defaultReadCode+0x24>
movsbl (%rbx),%ecx
mov    %ecx,(%r14)
cltq
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffffffffffff,%rax
ret

LLVM IR (-O0):
define i64 @defaultReadCode(i32 %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%11 = load i64, i64* %8
%12 = icmp ult i64 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %4
store i64 -1, i64* %5
br label %30
14: ; preds = %4
%15 = load i32, i32* %6
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = call i32 @read(i32 %15, i8* %17, i32 1)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i32*, i32** %9
store i32 %25, i32* %26
br label %27
27: ; preds = %21, %14
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
store i64 %29, i64* %5
br label %30
30: ; preds = %27, %13
%31 = load i64, i64* %5
ret i64 %31
}

LLVM IR (-O2):
define i64 @defaultReadCode(i32 %0, i8* nocapture %1, i64 %2, i32* nocapture writeonly %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %14, label %6
6: ; preds = %4
%7 = tail call i32 @read(i32 %0, i8* %1, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
store i32 %11, i32* %3
br label %12
12: ; preds = %9, %6
%13 = sext i32 %7 to i64
br label %14
14: ; preds = %4, %12
%15 = phi i64 [ %13, %12 ], [ -1, %4 ]
ret i64 %15
}