#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 *, ...);
int strlen(char *);
char *strtok(char *, char *);
void list_wrap(char *s, int l, int r, int v) {
  int i;
  static int c = 0;
  static int m = 0;
  char *t;
  if (s == NULL) {
    for (i = 0; i < l; i++)
      printf(" ");
    c = l;
    m = r;
    return;
  } else if (c > l) {
    c++;
    printf(v ? "," : " ");
  }
  t = strtok(s, " ");
  while (t) {
    if ((c + strlen(t) + 1) > m) {
      c = l;
      printf("\n");
      for (i = 0; i < l; i++) {
        printf(" ");
      }
    } else if (c > l) {
      printf(" ");
    }
    c += strlen(t) + 1;
    printf("%s", t);
    t = strtok(NULL, " ");
  }
}


x86 assembly (clang, -O0):
<list_wrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1196 <list_wrap+0x66>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117f <list_wrap+0x4f>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1157 <list_wrap+0x27>
mov    -0xc(%rbp),%eax
mov    %eax,0x2eb4(%rip)
mov    -0x10(%rbp),%eax
mov    %eax,0x2eaf(%rip)
jmp    12cf <list_wrap+0x19f>
mov    0x2ea0(%rip),%eax
cmp    -0xc(%rbp),%eax
jle    11d3 <list_wrap+0xa3>
mov    0x2e91(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e88(%rip)
mov    -0x14(%rbp),%ecx
lea    0xe42(%rip),%rdi
lea    0xe3d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d8 <list_wrap+0xa8>
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12cf <list_wrap+0x19f>
mov    0x2e3f(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    0x2e27(%rip),%eax
jle    126a <list_wrap+0x13a>
mov    -0xc(%rbp),%eax
mov    %eax,0x2e14(%rip)
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1265 <list_wrap+0x135>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123d <list_wrap+0x10d>
jmp    128c <list_wrap+0x15c>
mov    0x2dcc(%rip),%eax
cmp    -0xc(%rbp),%eax
jle    1287 <list_wrap+0x157>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128c <list_wrap+0x15c>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
add    0x2d9e(%rip),%eax
mov    %eax,0x2d98(%rip)
mov    -0x20(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd3f(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11ec <list_wrap+0xbc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_wrap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
test   %rdi,%rdi
je     1264 <list_wrap+0x124>
mov    %rdi,%rbx
mov    0x2ee7(%rip),%eax
cmp    %r12d,%eax
jle    1186 <list_wrap+0x46>
add    $0x1,%eax
mov    %eax,0x2ed9(%rip)
test   %ecx,%ecx
lea    0xe8c(%rip),%rax
lea    0xe87(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     128d <list_wrap+0x14d>
mov    %rax,%rbx
lea    0xe5c(%rip),%r14
lea    0xe51(%rip),%r15
jmp    11fc <list_wrap+0xbc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0x2e76(%rip),%ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,0x2e6b(%rip)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     128d <list_wrap+0x14d>
mov    0x2e42(%rip),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
cmp    0x2e36(%rip),%eax
jge    1230 <list_wrap+0xf0>
cmp    %r12d,0x2e29(%rip)
jle    11c0 <list_wrap+0x80>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11c0 <list_wrap+0x80>
nopl   0x0(%rax)
mov    %r12d,0x2e0d(%rip)
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r12d,%r12d
jle    11c0 <list_wrap+0x80>
mov    %r12d,%ebp
nopl   (%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1250 <list_wrap+0x110>
jmp    11c0 <list_wrap+0x80>
mov    %edx,%r14d
test   %r12d,%r12d
jle    127f <list_wrap+0x13f>
mov    %r12d,%ebx
nop
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    1270 <list_wrap+0x130>
mov    %r12d,0x2dbe(%rip)
mov    %r14d,0x2dbb(%rip)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@list_wrap.c = internal global i32 0
@list_wrap.m = internal global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define void @list_wrap(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %26
13: ; preds = %4
store i32 0, i32* %9
br label %14
14: ; preds = %20, %13
%15 = load i32, i32* %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18
%21 = load i32, i32* %9
%22 = add nsw i32 %21, 1
store i32 %22, i32* %9
br label %14
23: ; preds = %14
%24 = load i32, i32* %6
store i32 %24, i32* @list_wrap.c
%25 = load i32, i32* %7
store i32 %25, i32* @list_wrap.m
br label %82
26: ; preds = %4
%27 = load i32, i32* @list_wrap.c
%28 = load i32, i32* %6
%29 = icmp sgt i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i32, i32* @list_wrap.c
%32 = add nsw i32 %31, 1
store i32 %32, i32* @list_wrap.c
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%37 = call i32 (i8*, ...) @printf(i8* %36)
br label %38
38: ; preds = %30, %26
br label %39
39: ; preds = %38
%40 = load i8*, i8** %5
%41 = call i8* @strtok(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %10
br label %42
42: ; preds = %73, %39
%43 = load i8*, i8** %10
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %82
45: ; preds = %42
%46 = load i32, i32* @list_wrap.c
%47 = load i8*, i8** %10
%48 = call i32 @strlen(i8* %47)
%49 = add nsw i32 %46, %48
%50 = add nsw i32 %49, 1
%51 = load i32, i32* @list_wrap.m
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %66
53: ; preds = %45
%54 = load i32, i32* %6
store i32 %54, i32* @list_wrap.c
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %56
56: ; preds = %62, %53
%57 = load i32, i32* %9
%58 = load i32, i32* %6
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %62
62: ; preds = %60
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %56
65: ; preds = %56
br label %73
66: ; preds = %45
%67 = load i32, i32* @list_wrap.c
%68 = load i32, i32* %6
%69 = icmp sgt i32 %67, %68
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
br label %73
73: ; preds = %72, %65
%74 = load i8*, i8** %10
%75 = call i32 @strlen(i8* %74)
%76 = add nsw i32 %75, 1
%77 = load i32, i32* @list_wrap.c
%78 = add nsw i32 %77, %76
store i32 %78, i32* @list_wrap.c
%79 = load i8*, i8** %10
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %79)
%81 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %81, i8** %10
br label %42
82: ; preds = %23, %42
ret void
}

LLVM IR (-O2):
@list_wrap.c = internal unnamed_addr global i32 0
@list_wrap.m = internal unnamed_addr global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c",\00"
@.str.3 = [3 x i8] c"%s\00"
define void @list_wrap(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %6, label %14
6: ; preds = %4
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %13
8: ; preds = %6, %8
%9 = phi i32 [ %11, %8 ], [ 0, %6 ]
%10 = tail call i32 @putchar(i32 32)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, %1
br i1 %12, label %13, label %8
13: ; preds = %8, %6
store i32 %1, i32* @list_wrap.c
store i32 %2, i32* @list_wrap.m
br label %54
14: ; preds = %4
%15 = load i32, i32* @list_wrap.c
%16 = icmp sgt i32 %15, %1
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = add nsw i32 %15, 1
store i32 %18, i32* @list_wrap.c
%19 = icmp eq i32 %3, 0
%20 = select i1 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %20)
br label %22
22: ; preds = %14, %17
%23 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %54, label %25
25: ; preds = %22
%26 = icmp sgt i32 %1, 0
br label %27
27: ; preds = %25, %46
%28 = phi i8* [ %23, %25 ], [ %52, %46 ]
%29 = load i32, i32* @list_wrap.c
%30 = tail call i32 @strlen(i8* %28)
%31 = add nsw i32 %30, %29
%32 = load i32, i32* @list_wrap.m
%33 = icmp slt i32 %31, %32
br i1 %33, label %41, label %34
34: ; preds = %27
store i32 %1, i32* @list_wrap.c
%35 = tail call i32 @putchar(i32 10)
br i1 %26, label %36, label %46
36: ; preds = %34, %36
%37 = phi i32 [ %39, %36 ], [ 0, %34 ]
%38 = tail call i32 @putchar(i32 32)
%39 = add nuw nsw i32 %37, 1
%40 = icmp eq i32 %39, %1
br i1 %40, label %46, label %36
41: ; preds = %27
%42 = load i32, i32* @list_wrap.c
%43 = icmp sgt i32 %42, %1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @putchar(i32 32)
br label %46
46: ; preds = %36, %34, %41, %44
%47 = tail call i32 @strlen(i8* %28)
%48 = add nsw i32 %47, 1
%49 = load i32, i32* @list_wrap.c
%50 = add nsw i32 %48, %49
store i32 %50, i32* @list_wrap.c
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%52 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %27
54: ; preds = %46, %22, %13
ret void
}