#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, size_t, int /*<<< orphan*/ *);
int write_to_file(uint8_t *data, size_t data_len, FILE *f) {
  while (data_len > 0) {
    size_t bytes = fwrite(data, 1, data_len, f);
    if (bytes == 0) {
      return 0;
    }
    data += bytes;
    data_len -= bytes;
  }
  return 1;
}


x86 assembly (clang, -O0):
<write_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1184 <write_to_file+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fwrite@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1160 <write_to_file+0x50>
movl   $0x0,-0x4(%rbp)
jmp    118b <write_to_file+0x7b>
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <write_to_file+0x14>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
test   %rbp,%rbp
je     1157 <write_to_file+0x47>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1030 <fwrite@plt>
sub    %rax,%rbp
lea    (%rbx,%rax,4),%rbx
test   %rax,%rax
jne    1130 <write_to_file+0x20>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @write_to_file(i32* nocapture %0, i64 %1, i32* nocapture %2) {
br label %4
4: ; preds = %8, %3
%5 = phi i64 [ %1, %3 ], [ %12, %8 ]
%6 = phi i32* [ %0, %3 ], [ %11, %8 ]
%7 = icmp eq i64 %5, 0
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i64 @fwrite(i32* %6, i32 1, i64 %5, i32* %2)
%10 = icmp eq i64 %9, 0
%11 = getelementptr inbounds i32, i32* %6, i64 %9
%12 = sub i64 %5, %9
br i1 %10, label %13, label %4
13: ; preds = %8, %4
%14 = phi i32 [ 0, %8 ], [ 1, %4 ]
ret i32 %14
}