#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 */
struct binio_file {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ binio_close(struct binio_file *);
struct binio_file *binio_from_file(char const *, char *);
size_t packbits_write(struct binio_file *, unsigned char const *, size_t);
size_t packbits_write_file(const char *file, const unsigned char *data,
                           size_t size) {
  struct binio_file *bf;
  size_t out_size;
  assert(file != NULL);
  assert(data != NULL);
  assert(size > 0);
  if ((bf = binio_from_file(file, "wb")) == NULL) {
    return 0;
  }
  out_size = packbits_write(bf, data, size);
  binio_close(bf);
  return out_size;
}


x86 assembly (clang, -O0):
<packbits_write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <binio_from_file@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b5 <packbits_write_file+0x75>
movq   $0x0,-0x8(%rbp)
jmp    11db <packbits_write_file+0x9b>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <packbits_write@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <binio_close@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<packbits_write_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
lea    0xe81(%rip),%rsi
mov    %rbx,%rdi
call   1030 <binio_from_file@plt>
test   %rax,%rax
je     11ad <packbits_write_file+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <packbits_write@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <binio_close@plt>
mov    %r14,%rax
jmp    11af <packbits_write_file+0x6f>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.binio_file = type { i32 }
@.str = [3 x i8] c"wb\00"
define i64 @packbits_write_file(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.binio_file*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* %7
%19 = icmp ugt i64 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %5
%23 = call %struct.binio_file* @binio_from_file(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store %struct.binio_file* %23, %struct.binio_file** %8
%24 = icmp eq %struct.binio_file* %23, null
br i1 %24, label %25, label %26
25: ; preds = %3
store i64 0, i64* %4
br label %34
26: ; preds = %3
%27 = load %struct.binio_file*, %struct.binio_file** %8
%28 = load i8*, i8** %6
%29 = load i64, i64* %7
%30 = call i64 @packbits_write(%struct.binio_file* %27, i8* %28, i64 %29)
store i64 %30, i64* %9
%31 = load %struct.binio_file*, %struct.binio_file** %8
%32 = call i32 @binio_close(%struct.binio_file* %31)
%33 = load i64, i64* %9
store i64 %33, i64* %4
br label %34
34: ; preds = %26, %25
%35 = load i64, i64* %4
ret i64 %35
}

LLVM IR (-O2):
%struct.binio_file = type { i32 }
@.str = [3 x i8] c"wb\00"
define i64 @packbits_write_file(i8* %0, i8* %1, i64 %2) {
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i8* %1, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp ne i64 %2, 0
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call %struct.binio_file* @binio_from_file(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq %struct.binio_file* %13, null
br i1 %14, label %18, label %15
15: ; preds = %3
%16 = tail call i64 @packbits_write(%struct.binio_file* %13, i8* %1, i64 %2)
%17 = tail call i32 @binio_close(%struct.binio_file* %13)
br label %18
18: ; preds = %3, %15
%19 = phi i64 [ %16, %15 ], [ 0, %3 ]
ret i64 %19
}