#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 scalar_t__ ssize_t;

/* Variables and functions */
size_t SSIZE_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int write(int /*<<< orphan*/, char *, int);
void writelines(char *buf, size_t buflen, __attribute__((unused)) void *info) {
  assert(buflen > 0);
  assert(buflen < SSIZE_MAX);
  if (write(fileno(stdout), buf, buflen) < (ssize_t)buflen) {
    perror("pcat: write()");
    exit(1);
  }
  if (buf[buflen - 1] != '\n' && write(fileno(stdout), "\n", 1) < 1) {
    perror("pcat: write()");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<writelines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
call   1030 <write@plt>
cltq
cmp    -0x10(%rbp),%rax
jge    11d2 <writelines+0x82>
lea    0xe3d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     122b <writelines+0xdb>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
lea    0xe0c(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jge    122b <writelines+0xdb>
lea    0xde4(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writelines>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1040 <assert@plt>
mov    0x2e78(%rip),%rax
xor    %edi,%edi
cmp    %rbx,(%rax)
seta   %dil
call   1040 <assert@plt>
mov    0x2e53(%rip),%r15
mov    (%r15),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cltq
cmp    %rbx,%rax
jl     11cd <writelines+0x7d>
cmpb   $0xa,-0x1(%rbx,%r14,1)
je     11c7 <writelines+0x77>
mov    (%r15),%edi
call   1050 <fileno@plt>
lea    0xe57(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
test   %eax,%eax
jle    11cd <writelines+0x7d>
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SSIZE_MAX = global i64 0
@stdout = global i32 0
@.str = [14 x i8] c"pcat: write()\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @writelines(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%7 = load i64, i64* %5
%8 = icmp ugt i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i64, i64* %5
%12 = load i64, i64* @SSIZE_MAX
%13 = icmp ult i64 %11, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* @stdout
%17 = call i32 @fileno(i32 %16)
%18 = load i8*, i8** %4
%19 = load i64, i64* %5
%20 = trunc i64 %19 to i32
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
%22 = sext i32 %21 to i64
%23 = load i64, i64* %5
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %3
%29 = load i8*, i8** %4
%30 = load i64, i64* %5
%31 = sub i64 %30, 1
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 10
br i1 %35, label %36, label %44
36: ; preds = %28
%37 = load i32, i32* @stdout
%38 = call i32 @fileno(i32 %37)
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %36, %28
ret void
}

LLVM IR (-O2):
@SSIZE_MAX = global i64 0
@stdout = global i32 0
@.str = [14 x i8] c"pcat: write()\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @writelines(i8* nocapture %0, i64 %1, i8* nocapture readnone %2) {
%4 = icmp ne i64 %1, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i64, i64* @SSIZE_MAX
%8 = icmp ugt i64 %7, %1
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = load i32, i32* @stdout
%12 = tail call i32 @fileno(i32 %11)
%13 = trunc i64 %1 to i32
%14 = tail call i32 @write(i32 %12, i8* %0, i32 %13)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %15, %1
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = add i64 %1, -1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 10
br i1 %24, label %33, label %25
25: ; preds = %20
%26 = load i32, i32* @stdout
%27 = tail call i32 @fileno(i32 %26)
%28 = tail call i32 @write(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %25, %20
ret void
}