#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*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
char *wordwrap(char *, char *, int);
int main(int argc, char **argv) {
  char *strptr;
  char res[128];
  if (argc != 2) {
    puts("Usage: wraptest teststring");
    return 0;
  }
  for (strptr = wordwrap(res, argv[1], 16);;
       strptr = wordwrap(res, strptr, 16)) {
    printf("|%s|\r\n", res);
    if (strptr == NULL)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     116b <main+0x3b>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <main+0xa5>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x10,%edx
call   1050 <wordwrap@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11ab <main+0x7b>
jmp    11ce <main+0x9e>
jmp    11b0 <main+0x80>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1050 <wordwrap@plt>
mov    %rax,-0x18(%rbp)
jmp    1188 <main+0x58>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jne    11a5 <main+0x75>
mov    0x8(%rsi),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x10,%edx
call   1050 <wordwrap@plt>
mov    %rax,%rbx
lea    0xebc(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
test   %rbx,%rbx
je     11b1 <main+0x81>
mov    %rsp,%r14
lea    0xea5(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1050 <wordwrap@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
test   %rbx,%rbx
jne    1180 <main+0x50>
jmp    11b1 <main+0x81>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: wraptest teststring\00"
@.str.1 = [7 x i8] c"|%s|\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %30
12: ; preds = %2
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i8* @wordwrap(i8* %13, i8* %16, i32 16)
store i8* %17, i8** %6
br label %18
18: ; preds = %25, %12
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %18
br label %29
24: ; preds = %18
br label %25
25: ; preds = %24
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = call i8* @wordwrap(i8* %26, i8* %27, i32 16)
store i8* %28, i8** %6
br label %18
29: ; preds = %23
store i32 0, i32* %3
br label %30
30: ; preds = %29, %10
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [27 x i8] c"Usage: wraptest teststring\00"
@.str.1 = [7 x i8] c"|%s|\0D\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %19
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i8* @wordwrap(i8* %4, i8* %10, i32 16)
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = icmp eq i8* %11, null
br i1 %13, label %19, label %14
14: ; preds = %8, %14
%15 = phi i8* [ %16, %14 ], [ %11, %8 ]
%16 = call i8* @wordwrap(i8* %4, i8* %15, i32 16)
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%18 = icmp eq i8* %16, null
br i1 %18, label %19, label %14
19: ; preds = %14, %8, %6
ret i32 0
}