#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 *, size_t);
int read_skip_count(int fd, size_t count, char *buffer, size_t buffer_size) {
  size_t nleft;
  size_t ntry;
  int nread;
  nleft = count;
  while (nleft > 0) {
    if (nleft > buffer_size)
      ntry = buffer_size;
    else
      ntry = nleft;
    nread = read(fd, buffer, ntry);
    if (nread == -1)
      return (-1);
    else if ((size_t)nread != ntry)
      return (1);
    nleft -= nread;
  }
  return (0);
}


x86 assembly (clang, -O0):
<read_skip_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11b9 <read_skip_count+0xa9>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    1155 <read_skip_count+0x45>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    115d <read_skip_count+0x4d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <read@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1186 <read_skip_count+0x76>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <read_skip_count+0xb0>
movslq -0x34(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     11a0 <read_skip_count+0x90>
movl   $0x1,-0x4(%rbp)
jmp    11c0 <read_skip_count+0xb0>
jmp    11a5 <read_skip_count+0x95>
movslq -0x34(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    112f <read_skip_count+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_skip_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rsi,%rsi
je     1169 <read_skip_count+0x59>
mov    %rcx,%r13
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r12d
nop
cmp    %r13,%rbx
mov    %rbx,%rbp
cmova  %r13,%rbp
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
je     115b <read_skip_count+0x4b>
cltq
cmp    %rax,%rbp
jne    1163 <read_skip_count+0x53>
sub    %rax,%rbx
jne    1130 <read_skip_count+0x20>
jmp    1169 <read_skip_count+0x59>
mov    $0xffffffff,%r14d
jmp    1169 <read_skip_count+0x59>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_skip_count(i32 %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%13 = load i64, i64* %7
store i64 %13, i64* %10
br label %14
14: ; preds = %40, %4
%15 = load i64, i64* %10
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %45
17: ; preds = %14
%18 = load i64, i64* %10
%19 = load i64, i64* %9
%20 = icmp ugt i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load i64, i64* %9
store i64 %22, i64* %11
br label %25
23: ; preds = %17
%24 = load i64, i64* %10
store i64 %24, i64* %11
br label %25
25: ; preds = %23, %21
%26 = load i32, i32* %6
%27 = load i8*, i8** %8
%28 = load i64, i64* %11
%29 = call i32 @read(i32 %26, i8* %27, i64 %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 -1, i32* %5
br label %46
33: ; preds = %25
%34 = load i32, i32* %12
%35 = sext i32 %34 to i64
%36 = load i64, i64* %11
%37 = icmp ne i64 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 1, i32* %5
br label %46
39: ; preds = %33
br label %40
40: ; preds = %39
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = load i64, i64* %10
%44 = sub i64 %43, %42
store i64 %44, i64* %10
br label %14
45: ; preds = %14
store i32 0, i32* %5
br label %46
46: ; preds = %45, %38, %32
%47 = load i32, i32* %5
ret i32 %47
}

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