#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 */
size_t fwrite(char const *, int, size_t, int /*<<< orphan*/ *);
size_t strlen(char const *);
bool write_line(FILE *fp, const char *line) {
  size_t cnt = 0;
  size_t len = strlen(line);
  while (cnt < len) {
    size_t n = fwrite(line + cnt, 1, len - cnt, fp);
    if (n < len - cnt)
      return false;
    cnt += n;
  }
  return true;
}


x86 assembly (clang, -O0):
<write_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11a7 <write_line+0x87>
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
sub    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    1196 <write_line+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11ae <write_line+0x8e>
mov    -0x30(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1145 <write_line+0x25>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
xor    %ebx,%ebx
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rbp
sub    %rbx,%rbp
jbe    1177 <write_line+0x57>
lea    (%r12,%rbx,1),%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1040 <fwrite@plt>
add    %rax,%rbx
cmp    %rbp,%rax
jae    1150 <write_line+0x30>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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