#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 /*<<< orphan*/ cha_puts(char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
void fputsn(char *str, char *out, int n) {
  char buff[256];
  int len;
  while (n > 0) {
    len = (n <= 255 ? n : 255);
    memcpy(buff, str, len);
    buff[len] = '\0';
    cha_puts(buff, out);
    str += len;
    n -= len;
  }
}


x86 assembly (clang, -O0):
<fputsn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11d3 <fputsn+0xb3>
cmpl   $0xff,-0x14(%rbp)
jg     115b <fputsn+0x3b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x128(%rbp)
jmp    116b <fputsn+0x4b>
mov    $0xff,%eax
mov    %eax,-0x128(%rbp)
jmp    116b <fputsn+0x4b>
mov    -0x128(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1030 <memcpy@plt>
movslq -0x124(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <cha_puts@plt>
mov    -0x124(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x124(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <fputsn+0x16>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputsn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
test   %edx,%edx
jle    1171 <fputsn+0x51>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r12
xchg   %ax,%ax
cmp    $0xff,%ebp
mov    $0xff,%ebx
cmovb  %ebp,%ebx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <cha_puts@plt>
add    %rbx,%r15
sub    %ebx,%ebp
jg     1140 <fputsn+0x20>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fputsn(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %9
9: ; preds = %18, %3
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %9
%13 = load i32, i32* %6
%14 = icmp sle i32 %13, 255
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i32, i32* %6
br label %18
17: ; preds = %12
br label %18
18: ; preds = %17, %15
%19 = phi i32 [ %16, %15 ], [ 255, %17 ]
store i32 %19, i32* %8
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = load i32, i32* %8
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = load i8*, i8** %5
%29 = call i32 @cha_puts(i8* %27, i8* %28)
%30 = load i32, i32* %8
%31 = load i8*, i8** %4
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %4
%34 = load i32, i32* %8
%35 = load i32, i32* %6
%36 = sub nsw i32 %35, %34
store i32 %36, i32* %6
br label %9
37: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @fputsn(i8* %0, i8* %1, i32 %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %19
7: ; preds = %3, %7
%8 = phi i8* [ %16, %7 ], [ %0, %3 ]
%9 = phi i32 [ %17, %7 ], [ %2, %3 ]
%10 = icmp ult i32 %9, 255
%11 = select i1 %10, i32 %9, i32 255
%12 = call i32 @memcpy(i8* %5, i8* %8, i32 %11)
%13 = zext i32 %11 to i64
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @cha_puts(i8* %5, i8* %1)
%16 = getelementptr inbounds i8, i8* %8, i64 %13
%17 = sub nsw i32 %9, %11
%18 = icmp sgt i32 %17, 0
br i1 %18, label %7, label %19
19: ; preds = %7, %3
ret void
}