#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 */
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
void split_fwrite(char *out_buffer, int sz, int out_buffer_size, FILE *out_file,
                  int linesz) {
  int i;
  char *buffer = out_buffer;
  static int rem_size = 0;
  if (rem_size) {
    fputc('\n', out_file);
    buffer += rem_size;
  }
  for (i = out_buffer_size; i >= linesz; i -= linesz) {
    fwrite(buffer, sz, linesz, out_file);
    fputc('\n', out_file);
    buffer += linesz;
  }
  if (i > 0) {
    rem_size = linesz - i;
    fwrite(buffer, sz, i, out_file);
  }
}


x86 assembly (clang, -O0):
<split_fwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,0x2eeb(%rip)
je     1171 <split_fwrite+0x51>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    0x2ed1(%rip),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11c5 <split_fwrite+0xa5>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <fwrite@plt>
mov    -0x18(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
jmp    1177 <split_fwrite+0x57>
cmpl   $0x0,-0x20(%rbp)
jle    11ee <split_fwrite+0xce>
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,0x2e59(%rip)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1040 <fwrite@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_fwrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r12d
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
cmpl   $0x0,0x2ef4(%rip)
je     1159 <split_fwrite+0x39>
mov    $0xa,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
movslq 0x2ede(%rip),%rax
add    %rax,%rbx
cmp    %r12d,%ebp
jl     1199 <split_fwrite+0x79>
movslq %r12d,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1040 <fwrite@plt>
mov    $0xa,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
add    %r13,%rbx
sub    %r12d,%ebp
cmp    %r12d,%ebp
jge    1170 <split_fwrite+0x50>
test   %ebp,%ebp
jle    11c5 <split_fwrite+0xa5>
sub    %ebp,%r12d
mov    %r12d,0x2e8d(%rip)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fwrite@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@split_fwrite.rem_size = internal global i32 0
define void @split_fwrite(i8* %0, i32 %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%13 = load i8*, i8** %6
store i8* %13, i8** %12
%14 = load i32, i32* @split_fwrite.rem_size
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %5
%17 = load i32*, i32** %9
%18 = call i32 @fputc(i8 signext 10, i32* %17)
%19 = load i32, i32* @split_fwrite.rem_size
%20 = load i8*, i8** %12
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %12
br label %23
23: ; preds = %16, %5
%24 = load i32, i32* %8
store i32 %24, i32* %11
br label %25
25: ; preds = %41, %23
%26 = load i32, i32* %11
%27 = load i32, i32* %10
%28 = icmp sge i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i8*, i8** %12
%31 = load i32, i32* %7
%32 = load i32, i32* %10
%33 = load i32*, i32** %9
%34 = call i32 @fwrite(i8* %30, i32 %31, i32 %32, i32* %33)
%35 = load i32*, i32** %9
%36 = call i32 @fputc(i8 signext 10, i32* %35)
%37 = load i32, i32* %10
%38 = load i8*, i8** %12
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %12
br label %41
41: ; preds = %29
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = sub nsw i32 %43, %42
store i32 %44, i32* %11
br label %25
45: ; preds = %25
%46 = load i32, i32* %11
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load i32, i32* %10
%50 = load i32, i32* %11
%51 = sub nsw i32 %49, %50
store i32 %51, i32* @split_fwrite.rem_size
%52 = load i8*, i8** %12
%53 = load i32, i32* %7
%54 = load i32, i32* %11
%55 = load i32*, i32** %9
%56 = call i32 @fwrite(i8* %52, i32 %53, i32 %54, i32* %55)
br label %57
57: ; preds = %48, %45
ret void
}

LLVM IR (-O2):
@split_fwrite.rem_size = internal unnamed_addr global i32 0
define void @split_fwrite(i8* nocapture %0, i32 %1, i32 %2, i32* nocapture %3, i32 %4) {
%6 = load i32, i32* @split_fwrite.rem_size
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = tail call i32 @fputc(i8 signext 10, i32* %3)
%10 = load i32, i32* @split_fwrite.rem_size
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
br label %13
13: ; preds = %8, %5
%14 = phi i8* [ %12, %8 ], [ %0, %5 ]
%15 = icmp slt i32 %2, %4
br i1 %15, label %26, label %16
16: ; preds = %13
%17 = sext i32 %4 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i8* [ %14, %16 ], [ %23, %18 ]
%20 = phi i32 [ %2, %16 ], [ %24, %18 ]
%21 = tail call i32 @fwrite(i8* %19, i32 %1, i32 %4, i32* %3)
%22 = tail call i32 @fputc(i8 signext 10, i32* %3)
%23 = getelementptr inbounds i8, i8* %19, i64 %17
%24 = sub nsw i32 %20, %4
%25 = icmp slt i32 %24, %4
br i1 %25, label %26, label %18
26: ; preds = %18, %13
%27 = phi i32 [ %2, %13 ], [ %24, %18 ]
%28 = phi i8* [ %14, %13 ], [ %23, %18 ]
%29 = icmp sgt i32 %27, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = sub nsw i32 %4, %27
store i32 %31, i32* @split_fwrite.rem_size
%32 = tail call i32 @fwrite(i8* %28, i32 %1, i32 %27, i32* %3)
br label %33
33: ; preds = %30, %26
ret void
}