#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 */
scalar_t__ fio_write_16(int /*<<< orphan*/ *, int /*<<< orphan*/,
                        int /*<<< orphan*/);
scalar_t__ fio_write_32(int /*<<< orphan*/ *, int /*<<< orphan*/,
                        int /*<<< orphan*/);
scalar_t__ fio_write_8(int /*<<< orphan*/ *, int /*<<< orphan*/);
int fio_write_zeroes(FILE *f, int n) {
  while (n > 0) {
    if (n >= 4) {
      if (fio_write_32(f, 0, 0) != 0)
        return -1;
      n -= 4;
    } else if (n >= 2) {
      if (fio_write_16(f, 0, 0) != 0)
        return -1;
      n -= 2;
    } else {
      if (fio_write_8(f, 0) != 0)
        return -1;
      n--;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<fio_write_zeroes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11f3 <fio_write_zeroes+0xc3>
cmpl   $0x4,-0x14(%rbp)
jl     1184 <fio_write_zeroes+0x54>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1050 <fio_write_32@plt>
cmp    $0x0,%rax
je     1176 <fio_write_zeroes+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <fio_write_zeroes+0xca>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <fio_write_zeroes+0xbe>
cmpl   $0x2,-0x14(%rbp)
jl     11bf <fio_write_zeroes+0x8f>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <fio_write_16@plt>
cmp    $0x0,%rax
je     11b1 <fio_write_zeroes+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <fio_write_zeroes+0xca>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    11e9 <fio_write_zeroes+0xb9>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <fio_write_8@plt>
cmp    $0x0,%rax
je     11e0 <fio_write_zeroes+0xb0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fa <fio_write_zeroes+0xca>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11ee <fio_write_zeroes+0xbe>
jmp    113f <fio_write_zeroes+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fio_write_zeroes>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
jle    1181 <fio_write_zeroes+0x51>
mov    %esi,%ebp
mov    %rdi,%rbx
jmp    115a <fio_write_zeroes+0x2a>
xchg   %ax,%ax
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <fio_write_32@plt>
mov    $0xfffffffc,%ecx
test   %rax,%rax
jne    117a <fio_write_zeroes+0x4a>
add    %ecx,%ebp
je     1181 <fio_write_zeroes+0x51>
cmp    $0x4,%ebp
jae    1140 <fio_write_zeroes+0x10>
cmp    $0x2,%ebp
jb     118a <fio_write_zeroes+0x5a>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <fio_write_16@plt>
mov    $0xfffffffe,%ecx
test   %rax,%rax
je     1156 <fio_write_zeroes+0x26>
mov    $0xffffffff,%eax
jmp    1183 <fio_write_zeroes+0x53>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fio_write_8@plt>
neg    %rax
sbb    %eax,%eax
jmp    1183 <fio_write_zeroes+0x53>

LLVM IR (-O0):
define i32 @fio_write_zeroes(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
br label %6
6: ; preds = %40, %2
%7 = load i32, i32* %5
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %41
9: ; preds = %6
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 4
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32*, i32** %4
%14 = call i64 @fio_write_32(i32* %13, i32 0, i32 0)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %3
br label %42
17: ; preds = %12
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 4
store i32 %19, i32* %5
br label %40
20: ; preds = %9
%21 = load i32, i32* %5
%22 = icmp sge i32 %21, 2
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = load i32*, i32** %4
%25 = call i64 @fio_write_16(i32* %24, i32 0, i32 0)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %3
br label %42
28: ; preds = %23
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 2
store i32 %30, i32* %5
br label %39
31: ; preds = %20
%32 = load i32*, i32** %4
%33 = call i64 @fio_write_8(i32* %32, i32 0)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 -1, i32* %3
br label %42
36: ; preds = %31
%37 = load i32, i32* %5
%38 = add nsw i32 %37, -1
store i32 %38, i32* %5
br label %39
39: ; preds = %36, %28
br label %40
40: ; preds = %39, %17
br label %6
41: ; preds = %6
store i32 0, i32* %3
br label %42
42: ; preds = %41, %35, %27, %16
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @fio_write_zeroes(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %23
4: ; preds = %2, %19
%5 = phi i32 [ %21, %19 ], [ %1, %2 ]
%6 = icmp ugt i32 %5, 3
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i64 @fio_write_32(i32* %0, i32 0, i32 0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %19, label %23
10: ; preds = %4
%11 = icmp ugt i32 %5, 1
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = tail call i64 @fio_write_16(i32* %0, i32 0, i32 0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %23
15: ; preds = %10
%16 = tail call i64 @fio_write_8(i32* %0, i32 0)
%17 = icmp ne i64 %16, 0
%18 = sext i1 %17 to i32
br label %23
19: ; preds = %12, %7
%20 = phi i32 [ -4, %7 ], [ -2, %12 ]
%21 = add nsw i32 %5, %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %4
23: ; preds = %7, %12, %19, %15, %2
%24 = phi i32 [ 0, %2 ], [ %18, %15 ], [ 0, %19 ], [ -1, %12 ], [ -1, %7 ]
ret i32 %24
}