#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 */

/* Variables and functions */
int write(int, char *, size_t);
int writefullnl(int fd, char *buf, size_t count) {
  int r = 0;
  *(buf + count++) = '\n';
  while (count > 0) {
    r = write(fd, buf + r, count - r);
    if (r < 0)
      return r;
    count -= r;
  }
  return 0;
}


x86 assembly (clang, -O0):
<writefullnl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movb   $0xa,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
jbe    1196 <writefullnl+0x86>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
movslq -0x1c(%rbp),%rax
sub    %rax,%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1182 <writefullnl+0x72>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <writefullnl+0x8d>
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <writefullnl+0x31>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writefullnl>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
xor    %eax,%eax
movb   $0xa,(%rsi,%rdx,1)
inc    %rbx
je     1150 <writefullnl+0x40>
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
nopl   0x0(%rax)
mov    %eax,%eax
lea    (%r14,%rax,1),%rsi
mov    %rbx,%rdx
sub    %rax,%rdx
mov    %ebp,%edi
call   1030 <write@plt>
test   %eax,%eax
js     1150 <writefullnl+0x40>
mov    %eax,%ecx
sub    %rcx,%rbx
jne    1130 <writefullnl+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @writefullnl(i32 %0, i8* nocapture %1, i64 %2) {
%4 = add i64 %2, 1
%5 = getelementptr inbounds i8, i8* %1, i64 %2
store i8 10, i8* %5
%6 = icmp eq i64 %4, 0
br i1 %6, label %19, label %9
7: ; preds = %9
%8 = icmp eq i64 %18, 0
br i1 %8, label %19, label %9
9: ; preds = %3, %7
%10 = phi i32 [ %15, %7 ], [ 0, %3 ]
%11 = phi i64 [ %18, %7 ], [ %4, %3 ]
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = sub i64 %11, %12
%15 = tail call i32 @write(i32 %0, i8* %13, i64 %14)
%16 = icmp slt i32 %15, 0
%17 = zext i32 %15 to i64
%18 = sub i64 %11, %17
br i1 %16, label %19, label %7
19: ; preds = %9, %7, %3
%20 = phi i32 [ 0, %3 ], [ 0, %7 ], [ %15, %9 ]
ret i32 %20
}