#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 newload(char *, int);
int filbuf(char *buf, int count) {
  static int c, m;
  c = m = newload(buf, count);
  if (m <= 0)
    return 0;
  while (m < count)
    buf[m++] = 26;
  return c;
}


x86 assembly (clang, -O0):
<filbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <newload@plt>
mov    %eax,0x2eff(%rip)
mov    %eax,0x2ef5(%rip)
cmpl   $0x0,0x2ef2(%rip)
jg     1150 <filbuf+0x40>
movl   $0x0,-0x4(%rbp)
jmp    118e <filbuf+0x7e>
jmp    1155 <filbuf+0x45>
mov    0x2ed5(%rip),%eax
cmp    -0x14(%rbp),%eax
jge    1185 <filbuf+0x75>
mov    -0x10(%rbp),%rax
mov    0x2ec2(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2eb7(%rip)
movslq %ecx,%rcx
movb   $0x1a,(%rax,%rcx,1)
jmp    1155 <filbuf+0x45>
mov    0x2ea1(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filbuf>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <newload@plt>
test   %eax,%eax
jle    1156 <filbuf+0x36>
mov    %eax,%ebx
cmp    %ebp,%eax
jge    1158 <filbuf+0x38>
mov    %ebx,%eax
add    %rax,%r14
mov    %ebx,%edx
not    %edx
add    %ebp,%edx
add    $0x1,%rdx
mov    %r14,%rdi
mov    $0x1a,%esi
call   1030 <memset@plt>
jmp    1158 <filbuf+0x38>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@filbuf.c = internal global i32 0
@filbuf.m = internal global i32 0
define i32 @filbuf(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = load i32, i32* %5
%8 = call i32 @newload(i8* %6, i32 %7)
store i32 %8, i32* @filbuf.m
store i32 %8, i32* @filbuf.c
%9 = load i32, i32* @filbuf.m
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %25
12: ; preds = %2
br label %13
13: ; preds = %17, %12
%14 = load i32, i32* @filbuf.m
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i32, i32* @filbuf.m
%20 = add nsw i32 %19, 1
store i32 %20, i32* @filbuf.m
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 26, i8* %22
br label %13
23: ; preds = %13
%24 = load i32, i32* @filbuf.c
store i32 %24, i32* %3
br label %25
25: ; preds = %23, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @filbuf(i8* %0, i32 %1) {
%3 = tail call i32 @newload(i8* %0, i32 %1)
%4 = icmp slt i32 %3, 1
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = icmp slt i32 %3, %1
br i1 %6, label %7, label %14
7: ; preds = %5
%8 = zext i32 %3 to i64
%9 = getelementptr i8, i8* %0, i64 %8
%10 = xor i32 %3, -1
%11 = add i32 %10, %1
%12 = zext i32 %11 to i64
%13 = add nuw nsw i64 %12, 1
br label %14
14: ; preds = %5, %7, %2
%15 = phi i32 [ 0, %2 ], [ %3, %7 ], [ %3, %5 ]
ret i32 %15
}