#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 fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int commitChunk(unsigned char times, unsigned short value, FILE *out_fptr) {
  unsigned char buf[4];
  buf[0] = value;
  buf[1] = value >> 8;
  buf[2] = times;
  if (1 != fwrite(buf, 3, 1, out_fptr)) {
    perror("fwrite");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<commitChunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %dil,%cl
mov    %cl,-0x5(%rbp)
mov    %ax,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%ax
mov    %al,-0x14(%rbp)
movzwl -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x13(%rbp)
mov    -0x5(%rbp),%al
mov    %al,-0x12(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     118e <commitChunk+0x6e>
lea    0xe83(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <commitChunk+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<commitChunk>:
push   %rax
mov    %rdx,%rcx
mov    %esi,%eax
mov    %al,0x4(%rsp)
mov    %ah,0x5(%rsp)
mov    %dil,0x6(%rsp)
lea    0x4(%rsp),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1152 <commitChunk+0x32>
pop    %rcx
ret
lea    0xea7(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"fwrite\00"
define i32 @commitChunk(i8 zeroext %0, i16 zeroext %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i16
%7 = alloca i32*
%8 = alloca [4 x i8]
store i8 %0, i8* %5
store i16 %1, i16* %6
store i32* %2, i32** %7
%9 = load i16, i16* %6
%10 = trunc i16 %9 to i8
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
store i8 %10, i8* %11
%12 = load i16, i16* %6
%13 = zext i16 %12 to i32
%14 = ashr i32 %13, 8
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 %15, i8* %16
%17 = load i8, i8* %5
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 %17, i8* %18
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %7
%21 = call i32 @fwrite(i8* %19, i32 3, i32 1, i32* %20)
%22 = icmp ne i32 1, %21
br i1 %22, label %23, label %25
23: ; preds = %3
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %26
25: ; preds = %3
store i32 0, i32* %4
br label %26
26: ; preds = %25, %23
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"fwrite\00"
define i32 @commitChunk(i8 zeroext %0, i16 zeroext %1, i32* nocapture %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = trunc i16 %1 to i8
store i8 %6, i8* %5
%7 = lshr i16 %1, 8
%8 = trunc i16 %7 to i8
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %8, i8* %9
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %0, i8* %10
%11 = call i32 @fwrite(i8* %5, i32 3, i32 1, i32* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %3, %13
%16 = phi i32 [ -1, %13 ], [ 0, %3 ]
ret i32 %16
}