#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*/ printf(char *);
int read(int, char *, int);
void cfget_(int *lundes, int *medium, int *nwrec, int *nwtak, char *mbuf,
            int *astat) {
  int fildes;
  int nbdn, nbdo;
  if (medium) {
  }
  *astat = 0;
  if (*nwtak <= 0)
    return;
  fildes = *lundes;
  nbdo = *nwrec * 4;
  nbdn = read(fildes, mbuf, nbdo);
  if (nbdn == 0)
    goto heof;
  if (nbdn < 0)
    goto herror;
  *nwtak = (nbdn - 1) / 4 + 1;
  return;
heof:
  *astat = -1;
  return;
herror:
  *astat = 0;
  printf("error in CFGET\n");
  return;
}


x86 assembly (clang, -O0):
<cfget_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1150 <cfget_+0x30>
jmp    1150 <cfget_+0x30>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jg     116c <cfget_+0x4c>
jmp    11f4 <cfget_+0xd4>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
shl    $0x2,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    11a2 <cfget_+0x82>
jmp    11cf <cfget_+0xaf>
cmpl   $0x0,-0x38(%rbp)
jge    11b1 <cfget_+0x91>
jmp    11de <cfget_+0xbe>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f4 <cfget_+0xd4>
mov    -0x30(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    11f4 <cfget_+0xd4>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
lea    0xe11(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfget_>:
push   %r14
push   %rbx
push   %rax
movl   $0x0,(%r9)
cmpl   $0x0,(%rcx)
jle    115f <cfget_+0x3f>
mov    %r9,%rbx
mov    %rcx,%r14
mov    (%rdi),%edi
mov    (%rdx),%edx
shl    $0x2,%edx
mov    %r8,%rsi
call   1040 <read@plt>
test   %eax,%eax
je     1159 <cfget_+0x39>
js     1167 <cfget_+0x47>
add    $0xffffffff,%eax
shr    $0x2,%eax
add    $0x1,%eax
mov    %eax,(%r14)
jmp    115f <cfget_+0x3f>
movl   $0xffffffff,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movl   $0x0,(%rbx)
lea    0xe8c(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"error in CFGET\0A\00"
define void @cfget_(i32* %0, i32* %1, i32* %2, i32* %3, i8* %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i8* %4, i8** %11
store i32* %5, i32** %12
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %6
br label %19
19: ; preds = %18, %6
%20 = load i32*, i32** %12
store i32 0, i32* %20
%21 = load i32*, i32** %10
%22 = load i32, i32* %21
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %53
25: ; preds = %19
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
store i32 %27, i32* %13
%28 = load i32*, i32** %9
%29 = load i32, i32* %28
%30 = mul nsw i32 %29, 4
store i32 %30, i32* %15
%31 = load i32, i32* %13
%32 = load i8*, i8** %11
%33 = load i32, i32* %15
%34 = call i32 @read(i32 %31, i8* %32, i32 %33)
store i32 %34, i32* %14
%35 = load i32, i32* %14
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %25
br label %48
38: ; preds = %25
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
br label %50
42: ; preds = %38
%43 = load i32, i32* %14
%44 = sub nsw i32 %43, 1
%45 = sdiv i32 %44, 4
%46 = add nsw i32 %45, 1
%47 = load i32*, i32** %10
store i32 %46, i32* %47
br label %53
48: ; preds = %37
%49 = load i32*, i32** %12
store i32 -1, i32* %49
br label %53
50: ; preds = %41
%51 = load i32*, i32** %12
store i32 0, i32* %51
%52 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %53
53: ; preds = %50, %48, %42, %24
ret void
}

LLVM IR (-O2):
@str = [15 x i8] c"error in CFGET\00"
define void @cfget_(i32* nocapture %0, i32* nocapture readnone %1, i32* nocapture %2, i32* nocapture %3, i8* nocapture %4, i32* nocapture writeonly %5) {
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = load i32, i32* %0
%11 = load i32, i32* %2
%12 = shl nsw i32 %11, 2
%13 = tail call i32 @read(i32 %10, i8* %4, i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = icmp slt i32 %13, 0
br i1 %16, label %22, label %17
17: ; preds = %15
%18 = add nsw i32 %13, -1
%19 = lshr i32 %18, 2
%20 = add nuw nsw i32 %19, 1
store i32 %20, i32* %3
br label %24
21: ; preds = %9
store i32 -1, i32* %5
br label %24
22: ; preds = %15
store i32 0, i32* %5
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %6, %22, %21, %17
ret void
}