#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*/ putchar(char const);
short strlen(char const *);
void linewrap_print(const char *output) {
  short int i = 0;
  short line_length = 0;
  short length = strlen(output);
  for (i = 0; i < length; ++i) {
    if (line_length == 40) {
      putchar('\n');
      line_length = 0;
    }
    putchar(output[i]);
    if (output[i] == '\n') {
      line_length = 0;
    } else {
      line_length++;
    }
  }
}


x86 assembly (clang, -O0):
<linewrap_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movw   $0x0,-0xa(%rbp)
movw   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %ax,-0xe(%rbp)
movw   $0x0,-0xa(%rbp)
movswl -0xa(%rbp),%eax
movswl -0xe(%rbp),%ecx
cmp    %ecx,%eax
jge    11cd <linewrap_print+0xad>
movswl -0xc(%rbp),%eax
cmp    $0x28,%eax
jne    1178 <linewrap_print+0x58>
mov    $0xa,%edi
call   1030 <putchar@plt>
movw   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movswq -0xa(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
movswq -0xa(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ab <linewrap_print+0x8b>
movw   $0x0,-0xc(%rbp)
jmp    11b7 <linewrap_print+0x97>
mov    -0xc(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xc(%rbp)
jmp    11bc <linewrap_print+0x9c>
mov    -0xa(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xa(%rbp)
jmp    114b <linewrap_print+0x2b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linewrap_print>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
call   1040 <strlen@plt>
test   %ax,%ax
jle    1183 <linewrap_print+0x63>
movzwl %ax,%r14d
xor    %r15d,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    116f <linewrap_print+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmpb   $0xa,(%r12,%rbx,1)
cmove  %r15d,%ebp
add    $0x1,%rbx
cmp    %rbx,%r14
je     1183 <linewrap_print+0x63>
cmp    $0x28,%bp
jne    1150 <linewrap_print+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1150 <linewrap_print+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @linewrap_print(i8* %0) {
%2 = tail call signext i16 @strlen(i8* %0)
%3 = icmp sgt i16 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1
%5 = zext i16 %2 to i64
br label %6
6: ; preds = %4, %12
%7 = phi i64 [ 0, %4 ], [ %21, %12 ]
%8 = phi i16 [ 0, %4 ], [ %20, %12 ]
%9 = icmp eq i16 %8, 40
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @putchar(i8 signext 10)
br label %12
12: ; preds = %10, %6
%13 = phi i16 [ 0, %10 ], [ %8, %6 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %7
%15 = load i8, i8* %14
%16 = tail call i32 @putchar(i8 signext %15)
%17 = load i8, i8* %14
%18 = icmp eq i8 %17, 10
%19 = add i16 %13, 1
%20 = select i1 %18, i16 0, i16 %19
%21 = add nuw nsw i64 %7, 1
%22 = icmp eq i64 %21, %5
br i1 %22, label %23, label %6
23: ; preds = %12, %1
ret void
}