#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ sprint(char *, int, char *, int, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void line_wrap(char *string, int size, int column) {
  char *temp;
  char *sub;
  char *c;
  temp = malloc(size);
  for (sub = string; strlen(sub) > 80;) {
    for (c = sub + 78; c > sub && *c != ' '; c--)
      ;
    if (c <= sub)
      break;
    sub = c;
    strcpy(temp, sub);
    sprint(sub, size - (sub - string), "\n%*s %s", column, "", temp);
    sub++;
  }
  free(temp);
}


x86 assembly (clang, -O0):
<line_wrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x50,%eax
jle    1248 <line_wrap+0xf8>
mov    -0x20(%rbp),%rax
add    $0x4e,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x29(%rbp)
jbe    11b7 <line_wrap+0x67>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11c7 <line_wrap+0x77>
jmp    11dd <line_wrap+0x8d>
jmp    11cc <line_wrap+0x7c>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1194 <line_wrap+0x44>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     11f0 <line_wrap+0xa0>
jmp    1248 <line_wrap+0xf8>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
movslq -0xc(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r9
lea    0xdd5(%rip),%rdx
lea    0xdd5(%rip),%r8
call   1070 <sprint@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1176 <line_wrap+0x26>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line_wrap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x51,%eax
jl     11ee <line_wrap+0x9e>
lea    (%rbx,%rbp,1),%r15d
add    $0xffffffb2,%r15d
lea    0x4e(%rbx),%rbp
mov    %r15d,%r14d
sub    %ebx,%r14d
nopl   0x0(%rax)
cmpb   $0x20,0x0(%rbp)
je     11b0 <line_wrap+0x60>
add    $0xffffffffffffffff,%rbp
add    $0x1,%r14d
cmp    %rbx,%rbp
ja     1190 <line_wrap+0x40>
jmp    11ee <line_wrap+0x9e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
lea    0xe38(%rip),%rdx
mov    %r12d,%ecx
lea    0xe35(%rip),%r8
mov    %r13,%r9
call   1070 <sprint@plt>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rbx
cmp    $0x50,%eax
jg     1182 <line_wrap+0x32>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"\0A%*s %s\00"
@.str.1 = [1 x i8] zeroinitializer
define void @line_wrap(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %4
store i8* %12, i8** %8
br label %13
13: ; preds = %40, %3
%14 = load i8*, i8** %8
%15 = call i32 @strlen(i8* %14)
%16 = icmp sgt i32 %15, 80
br i1 %16, label %17, label %60
17: ; preds = %13
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 78
store i8* %19, i8** %9
br label %20
20: ; preds = %32, %17
%21 = load i8*, i8** %9
%22 = load i8*, i8** %8
%23 = icmp ugt i8* %21, %22
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 32
br label %29
29: ; preds = %24, %20
%30 = phi i1 [ false, %20 ], [ %28, %24 ]
br i1 %30, label %31, label %35
31: ; preds = %29
br label %32
32: ; preds = %31
%33 = load i8*, i8** %9
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %9
br label %20
35: ; preds = %29
%36 = load i8*, i8** %9
%37 = load i8*, i8** %8
%38 = icmp ule i8* %36, %37
br i1 %38, label %39, label %40
39: ; preds = %35
br label %60
40: ; preds = %35
%41 = load i8*, i8** %9
store i8* %41, i8** %8
%42 = load i8*, i8** %7
%43 = load i8*, i8** %8
%44 = call i32 @strcpy(i8* %42, i8* %43)
%45 = load i8*, i8** %8
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = load i8*, i8** %8
%49 = load i8*, i8** %4
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = sub nsw i64 %47, %52
%54 = trunc i64 %53 to i32
%55 = load i32, i32* %6
%56 = load i8*, i8** %7
%57 = call i32 @sprint(i8* %45, i32 %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %55, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %8
br label %13
60: ; preds = %39, %13
%61 = load i8*, i8** %7
%62 = call i32 @free(i8* %61)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"\0A%*s %s\00"
@.str.1 = [1 x i8] zeroinitializer
define void @line_wrap(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8* @malloc(i32 %1)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 80
br i1 %6, label %7, label %29
7: ; preds = %3
%8 = ptrtoint i8* %0 to i64
br label %9
9: ; preds = %7, %19
%10 = phi i8* [ %0, %7 ], [ %26, %19 ]
%11 = getelementptr inbounds i8, i8* %10, i64 78
br label %12
12: ; preds = %9, %16
%13 = phi i8* [ %11, %9 ], [ %17, %16 ]
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 32
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %13, i64 -1
%18 = icmp ugt i8* %17, %10
br i1 %18, label %12, label %29
19: ; preds = %12
%20 = tail call i32 @strcpy(i8* %4, i8* %13)
%21 = ptrtoint i8* %13 to i64
%22 = sub i64 %8, %21
%23 = trunc i64 %22 to i32
%24 = add i32 %23, %1
%25 = tail call i32 @sprint(i8* %13, i32 %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%26 = getelementptr inbounds i8, i8* %13, i64 1
%27 = tail call i32 @strlen(i8* %26)
%28 = icmp sgt i32 %27, 80
br i1 %28, label %9, label %29
29: ; preds = %19, %16, %3
%30 = tail call i32 @free(i8* %4)
ret void
}