#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 */
int /*<<< orphan*/ __CCAPRICE_FDOLOCK(int /*<<< orphan*/ *);
int /*<<< orphan*/ __CCAPRICE_FUNLOCK(int /*<<< orphan*/ *);
size_t __ccaprice_fwritex(void const *, size_t, int /*<<< orphan*/ *);
size_t fwrite(const void *p, size_t size, size_t count, FILE *fp) {
  size_t k;
  size_t l = size * count;
  if (!l)
    return l;
  __CCAPRICE_FDOLOCK(fp);
  k = __ccaprice_fwritex(p, l, fp);
  __CCAPRICE_FUNLOCK(fp);
  return k == l ? count : k / size;
}


x86 assembly (clang, -O0):
<fwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    116d <fwrite+0x3d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <fwrite+0x97>
mov    -0x28(%rbp),%rdi
call   1040 <__CCAPRICE_FDOLOCK@plt>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <__ccaprice_fwritex@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <__CCAPRICE_FUNLOCK@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    11af <fwrite+0x7f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11bf <fwrite+0x8f>
mov    -0x30(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
imul   %rsi,%rbx
test   %rbx,%rbx
je     1190 <fwrite+0x60>
mov    %rcx,%r13
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rcx,%rdi
call   1040 <__CCAPRICE_FDOLOCK@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1030 <__ccaprice_fwritex@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1050 <__CCAPRICE_FUNLOCK@plt>
cmp    %rbx,%r15
je     11a0 <fwrite+0x70>
mov    %r15,%rax
or     %r14,%rax
shr    $0x20,%rax
je     1195 <fwrite+0x65>
mov    %r15,%rax
xor    %edx,%edx
div    %r14
mov    %rax,%r12
jmp    11a0 <fwrite+0x70>
xor    %r12d,%r12d
jmp    11a0 <fwrite+0x70>
mov    %r15d,%eax
xor    %edx,%edx
div    %r14d
mov    %eax,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @fwrite(i8* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i32* %3, i32** %9
%12 = load i64, i64* %7
%13 = load i64, i64* %8
%14 = mul i64 %12, %13
store i64 %14, i64* %11
%15 = load i64, i64* %11
%16 = icmp ne i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %4
%18 = load i64, i64* %11
store i64 %18, i64* %5
br label %39
19: ; preds = %4
%20 = load i32*, i32** %9
%21 = call i32 @__CCAPRICE_FDOLOCK(i32* %20)
%22 = load i8*, i8** %6
%23 = load i64, i64* %11
%24 = load i32*, i32** %9
%25 = call i64 @__ccaprice_fwritex(i8* %22, i64 %23, i32* %24)
store i64 %25, i64* %10
%26 = load i32*, i32** %9
%27 = call i32 @__CCAPRICE_FUNLOCK(i32* %26)
%28 = load i64, i64* %10
%29 = load i64, i64* %11
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = load i64, i64* %8
br label %37
33: ; preds = %19
%34 = load i64, i64* %10
%35 = load i64, i64* %7
%36 = udiv i64 %34, %35
br label %37
37: ; preds = %33, %31
%38 = phi i64 [ %32, %31 ], [ %36, %33 ]
store i64 %38, i64* %5
br label %39
39: ; preds = %37, %17
%40 = load i64, i64* %5
ret i64 %40
}

LLVM IR (-O2):
define i64 @fwrite(i8* %0, i64 %1, i64 %2, i32* %3) {
%5 = mul i64 %2, %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = tail call i32 @__CCAPRICE_FDOLOCK(i32* %3)
%9 = tail call i64 @__ccaprice_fwritex(i8* %0, i64 %5, i32* %3)
%10 = tail call i32 @__CCAPRICE_FUNLOCK(i32* %3)
%11 = icmp eq i64 %9, %5
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = udiv i64 %9, %1
br label %14
14: ; preds = %12, %7, %4
%15 = phi i64 [ 0, %4 ], [ %13, %12 ], [ %2, %7 ]
ret i64 %15
}