#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*/ strncpy(char *, char *, int);
int write(int, char *, int);
int writeLine(int s, char *line, int total_size) {
  int acum = 0, size;
  char buffer[139];
  if (total_size > 139) {
    strncpy(buffer, line, 139);
    size = 139;
  } else {
    strncpy(buffer, line, total_size);
    size = total_size;
  }
  while ((size = write(s, buffer, size)) > 0) {
    if (size < 0)
      return size;
    acum += size;
    if (acum >= total_size)
      break;
    size = ((total_size - acum) >= 139) ? 139 : (total_size - acum) % 139;
    strncpy(buffer, line + acum, size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<writeLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8b,-0x14(%rbp)
jle    116a <writeLine+0x4a>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x8b,%edx
call   1030 <strncpy@plt>
movl   $0x8b,-0x1c(%rbp)
jmp    1183 <writeLine+0x63>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <writeLine+0x68>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1232 <writeLine+0x112>
cmpl   $0x0,-0x1c(%rbp)
jge    11bb <writeLine+0x9b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1239 <writeLine+0x119>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11d5 <writeLine+0xb5>
jmp    1232 <writeLine+0x112>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cmp    $0x8b,%eax
jl     11f6 <writeLine+0xd6>
mov    $0x8b,%edx
mov    %edx,-0xb4(%rbp)
jmp    120a <writeLine+0xea>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    $0x8b,%ecx
cltd
idiv   %ecx
mov    %edx,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1188 <writeLine+0x68>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %edx,%r13d
mov    %rsi,%r14
mov    %edi,%r15d
cmp    $0x8b,%edx
mov    $0x8b,%ebp
cmovl  %edx,%ebp
mov    %rsp,%r12
mov    %r12,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    11d0 <writeLine+0xb0>
xor    %ebx,%ebx
mov    %rsp,%r12
jmp    1191 <writeLine+0x71>
nopl   (%rax)
movslq %ebx,%rsi
add    %r14,%rsi
mov    %r12,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    11d0 <writeLine+0xb0>
mov    %ebx,%ecx
mov    %eax,%ebx
add    %ecx,%ebx
cmp    %r13d,%ebx
jge    11d0 <writeLine+0xb0>
mov    %r13d,%eax
sub    %ebx,%eax
mov    $0x8b,%ebp
cmp    $0x8a,%eax
jg     1170 <writeLine+0x50>
movslq %eax,%rcx
imul   $0x75ded953,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x8b,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,%ebp
jmp    1170 <writeLine+0x50>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @writeLine(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [139 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 139
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = getelementptr inbounds [139 x i8], [139 x i8]* %10, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 139)
store i32 139, i32* %9
br label %23
17: ; preds = %3
%18 = getelementptr inbounds [139 x i8], [139 x i8]* %10, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = call i32 @strncpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %7
store i32 %22, i32* %9
br label %23
23: ; preds = %17, %13
br label %24
24: ; preds = %54, %23
%25 = load i32, i32* %5
%26 = getelementptr inbounds [139 x i8], [139 x i8]* %10, i64 0, i64 0
%27 = load i32, i32* %9
%28 = call i32 @write(i32 %25, i8* %26, i32 %27)
store i32 %28, i32* %9
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %63
30: ; preds = %24
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* %9
store i32 %34, i32* %4
br label %64
35: ; preds = %30
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = add nsw i32 %37, %36
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = load i32, i32* %7
%41 = icmp sge i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %35
br label %63
43: ; preds = %35
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = sub nsw i32 %44, %45
%47 = icmp sge i32 %46, 139
br i1 %47, label %48, label %49
48: ; preds = %43
br label %54
49: ; preds = %43
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = sub nsw i32 %50, %51
%53 = srem i32 %52, 139
br label %54
54: ; preds = %49, %48
%55 = phi i32 [ 139, %48 ], [ %53, %49 ]
store i32 %55, i32* %9
%56 = getelementptr inbounds [139 x i8], [139 x i8]* %10, i64 0, i64 0
%57 = load i8*, i8** %6
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i32, i32* %9
%62 = call i32 @strncpy(i8* %56, i8* %60, i32 %61)
br label %24
63: ; preds = %42, %24
store i32 0, i32* %4
br label %64
64: ; preds = %63, %33
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
define i32 @writeLine(i32 %0, i8* %1, i32 %2) {
%4 = alloca [139 x i8]
%5 = getelementptr inbounds [139 x i8], [139 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %2, 139
%7 = select i1 %6, i32 %2, i32 139
%8 = call i32 @strncpy(i8* %5, i8* %1, i32 %7)
%9 = call i32 @write(i32 %0, i8* %5, i32 %7)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %3, %16
%12 = phi i32 [ %24, %16 ], [ %9, %3 ]
%13 = phi i32 [ %14, %16 ], [ 0, %3 ]
%14 = add nsw i32 %12, %13
%15 = icmp slt i32 %14, %2
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = sub nsw i32 %2, %14
%18 = srem i32 %17, 139
%19 = icmp slt i32 %17, 139
%20 = select i1 %19, i32 %18, i32 139
%21 = sext i32 %14 to i64
%22 = getelementptr inbounds i8, i8* %1, i64 %21
%23 = call i32 @strncpy(i8* %5, i8* %22, i32 %20)
%24 = call i32 @write(i32 %0, i8* %5, i32 %20)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %11, label %26
26: ; preds = %11, %16, %3
ret i32 0
}