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

/* Variables and functions */
size_t fwrite(int /*<<< orphan*/ *, int, unsigned int, int /*<<< orphan*/ *);
unsigned RangeCoderWriteStdio(__attribute__((unused)) void *user,
                              uint8_t **data, unsigned *size) {
  size_t n;
  n = fwrite(*data, 1, *size, (FILE *)user);
  if (n == *size) {
    return *size - n;
  }
  return *size - 1;
}


x86 assembly (clang, -O0):
<RangeCoderWriteStdio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
cmp    %rcx,%rax
jne    1168 <RangeCoderWriteStdio+0x58>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1174 <RangeCoderWriteStdio+0x64>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RangeCoderWriteStdio>:
push   %rbx
mov    %rdx,%rbx
mov    %rdi,%rcx
mov    (%rsi),%rdi
mov    (%rdx),%edx
mov    $0x1,%esi
call   1030 <fwrite@plt>
mov    (%rbx),%ecx
mov    %eax,%edx
neg    %edx
cmp    %rcx,%rax
mov    $0xffffffff,%eax
cmove  %edx,%eax
add    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @RangeCoderWriteStdio(i8* %0, i32** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
%9 = load i32**, i32*** %6
%10 = load i32*, i32** %9
%11 = load i32*, i32** %7
%12 = load i32, i32* %11
%13 = load i8*, i8** %5
%14 = bitcast i8* %13 to i32*
%15 = call i64 @fwrite(i32* %10, i32 1, i32 %12, i32* %14)
store i64 %15, i64* %8
%16 = load i64, i64* %8
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = zext i32 %18 to i64
%20 = icmp eq i64 %16, %19
br i1 %20, label %21, label %28
21: ; preds = %3
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = zext i32 %23 to i64
%25 = load i64, i64* %8
%26 = sub i64 %24, %25
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
br label %32
28: ; preds = %3
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = sub i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %28, %21
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @RangeCoderWriteStdio(i8* nocapture %0, i32** nocapture %1, i32* nocapture %2) {
%4 = load i32*, i32** %1
%5 = load i32, i32* %2
%6 = bitcast i8* %0 to i32*
%7 = tail call i64 @fwrite(i32* %4, i32 1, i32 %5, i32* %6)
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = icmp eq i64 %7, %9
%11 = trunc i64 %7 to i32
%12 = sub i32 0, %11
%13 = select i1 %10, i32 %12, i32 -1
%14 = add i32 %13, %8
ret i32 %14
}