#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__ EOF;
scalar_t__ fputc(char, int /*<<< orphan*/ *);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
  size_t size_in_chars = size * nmemb, i;
  for (i = 0; i < size_in_chars; i++)
    if (fputc(*(char *)((unsigned long)ptr + i), stream) == EOF)
      return i / size;
  return nmemb;
}


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,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    119c <fwrite+0x8c>
mov    -0x10(%rbp),%rax
add    -0x38(%rbp),%rax
mov    (%rax),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <fwrite+0x76>
mov    -0x38(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x8(%rbp)
jmp    11a4 <fwrite+0x94>
jmp    118b <fwrite+0x7b>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    113d <fwrite+0x2d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdx,%rbp
imul   %rsi,%rbp
test   %rbp,%rbp
je     1184 <fwrite+0x74>
mov    %rcx,%r12
mov    %rdi,%r13
mov    %rsi,(%rsp)
xor    %ebx,%ebx
mov    0x2eab(%rip),%r14
nopl   (%rax)
movsbl 0x0(%r13,%rbx,1),%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
cmp    (%r14),%rax
je     115e <fwrite+0x4e>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <fwrite+0x30>
jmp    1184 <fwrite+0x74>
mov    %rbx,%rax
mov    (%rsp),%rcx
or     %rcx,%rax
shr    $0x20,%rax
je     117b <fwrite+0x6b>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%r15
jmp    1184 <fwrite+0x74>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i64 0
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* %10
store i64 0, i64* %11
br label %15
15: ; preds = %35, %4
%16 = load i64, i64* %11
%17 = load i64, i64* %10
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load i8*, i8** %6
%21 = ptrtoint i8* %20 to i64
%22 = load i64, i64* %11
%23 = add i64 %21, %22
%24 = inttoptr i64 %23 to i8*
%25 = load i8, i8* %24
%26 = load i32*, i32** %9
%27 = call i64 @fputc(i8 signext %25, i32* %26)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %19
%31 = load i64, i64* %11
%32 = load i64, i64* %7
%33 = udiv i64 %31, %32
store i64 %33, i64* %5
br label %40
34: ; preds = %19
br label %35
35: ; preds = %34
%36 = load i64, i64* %11
%37 = add i64 %36, 1
store i64 %37, i64* %11
br label %15
38: ; preds = %15
%39 = load i64, i64* %8
store i64 %39, i64* %5
br label %40
40: ; preds = %38, %30
%41 = load i64, i64* %5
ret i64 %41
}

LLVM IR (-O2):
@EOF = global i64 0
define i64 @fwrite(i8* %0, i64 %1, i64 %2, i32* nocapture %3) {
%5 = mul i64 %2, %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %4
%8 = ptrtoint i8* %0 to i64
br label %9
9: ; preds = %7, %19
%10 = phi i64 [ 0, %7 ], [ %20, %19 ]
%11 = add i64 %10, %8
%12 = inttoptr i64 %11 to i8*
%13 = load i8, i8* %12
%14 = tail call i64 @fputc(i8 signext %13, i32* %3)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = udiv i64 %10, %1
br label %22
19: ; preds = %9
%20 = add nuw i64 %10, 1
%21 = icmp eq i64 %20, %5
br i1 %21, label %22, label %9
22: ; preds = %19, %4, %17
%23 = phi i64 [ %18, %17 ], [ %2, %4 ], [ %2, %19 ]
ret i64 %23
}