#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
unsigned long ULONG_MAX;
char getc(int /*<<< orphan*/ *);
unsigned long int countZB(FILE *fp, unsigned long int upper) {
  char c;
  long unsigned int zeros = 0;
  if (upper == 0)
    upper = ULONG_MAX;
  while ((c = getc(fp)) != EOF && zeros < upper && zeros < ULONG_MAX)
    if (c == '\0')
      zeros++;
  return zeros;
}


x86 assembly (clang, -O0):
<countZB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1141 <countZB+0x31>
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1146 <countZB+0x36>
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%ecx
mov    0x2e8c(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x21(%rbp)
je     1193 <countZB+0x83>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x21(%rbp)
jae    1193 <countZB+0x83>
mov    -0x20(%rbp),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
setb   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11a3 <countZB+0x93>
jmp    11c1 <countZB+0xb1>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    11bc <countZB+0xac>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1146 <countZB+0x36>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countZB>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2eaa(%rip),%r12
test   %rsi,%rsi
jne    112f <countZB+0x1f>
mov    (%r12),%r15
mov    %r14,%rdi
call   1030 <getc@plt>
mov    0x2eaa(%rip),%r13
xor    %ebx,%ebx
cmp    0x0(%r13),%al
je     117f <countZB+0x6f>
test   %r15,%r15
je     117f <countZB+0x6f>
cmpq   $0x0,(%r12)
je     117f <countZB+0x6f>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x1,%al
adc    $0x0,%rbx
mov    %r14,%rdi
call   1030 <getc@plt>
cmp    0x0(%r13),%al
je     117f <countZB+0x6f>
cmp    %r15,%rbx
jae    117f <countZB+0x6f>
cmp    (%r12),%rbx
jb     1160 <countZB+0x50>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@ULONG_MAX = global i64 0
@EOF = global i8 0
define i64 @countZB(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8
%6 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
store i64 0, i64* %6
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i64, i64* @ULONG_MAX
store i64 %10, i64* %4
br label %11
11: ; preds = %9, %2
br label %12
12: ; preds = %36, %11
%13 = load i32*, i32** %3
%14 = call signext i8 @getc(i32* %13)
store i8 %14, i8* %5
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i64, i64* %6
%21 = load i64, i64* %4
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i64, i64* %6
%25 = load i64, i64* @ULONG_MAX
%26 = icmp ult i64 %24, %25
br label %27
27: ; preds = %23, %19, %12
%28 = phi i1 [ false, %19 ], [ false, %12 ], [ %26, %23 ]
br i1 %28, label %29, label %37
29: ; preds = %27
%30 = load i8, i8* %5
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i64, i64* %6
%35 = add i64 %34, 1
store i64 %35, i64* %6
br label %36
36: ; preds = %33, %29
br label %12
37: ; preds = %27
%38 = load i64, i64* %6
ret i64 %38
}

LLVM IR (-O2):
@ULONG_MAX = global i64 0
@EOF = global i8 0
define i64 @countZB(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
%4 = load i64, i64* @ULONG_MAX
%5 = select i1 %3, i64 %4, i64 %1
%6 = tail call signext i8 @getc(i32* %0)
%7 = load i8, i8* @EOF
%8 = icmp ne i8 %6, %7
%9 = icmp ne i64 %5, 0
%10 = select i1 %8, i1 %9, i1 false
%11 = load i64, i64* @ULONG_MAX
%12 = icmp ne i64 %11, 0
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %28
14: ; preds = %2, %14
%15 = phi i8 [ %20, %14 ], [ %6, %2 ]
%16 = phi i64 [ %19, %14 ], [ 0, %2 ]
%17 = icmp eq i8 %15, 0
%18 = zext i1 %17 to i64
%19 = add nuw i64 %16, %18
%20 = tail call signext i8 @getc(i32* %0)
%21 = load i8, i8* @EOF
%22 = icmp ne i8 %20, %21
%23 = icmp ult i64 %19, %5
%24 = select i1 %22, i1 %23, i1 false
%25 = load i64, i64* @ULONG_MAX
%26 = icmp ult i64 %19, %25
%27 = select i1 %24, i1 %26, i1 false
br i1 %27, label %14, label %28
28: ; preds = %14, %2
%29 = phi i64 [ 0, %2 ], [ %19, %14 ]
ret i64 %29
}