void cut_and_print(char *string, char delimiter, char opt_short,
                   char opt_newline, char *prefix, char *suffix) {
  char *p, *s;
  char nl;
  nl = opt_newline ? '\n' : ' ';
  p = s = string;
  printf("%s%s", prefix, string);
  while ((p = strchr(p, delimiter))) {
    if (s < p)
      printf("%s%c%s", suffix, nl, prefix);
    while (s < p)
      putchar(*(s++));
    p++;
    s = (opt_short) ? p : string;
  }
  printf("%s%c%s%s%s\n", suffix, nl, prefix, s, suffix);
}


x86 assembly (clang, -O0):
<cut_and_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %cl,-0xa(%rbp)
mov    %al,-0xb(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movsbl -0xb(%rbp),%edx
mov    $0x20,%eax
mov    $0xa,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x31(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     123c <cut_and_print+0x10c>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11d0 <cut_and_print+0xa0>
mov    -0x20(%rbp),%rsi
movsbl -0x31(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d5 <cut_and_print+0xa5>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1201 <cut_and_print+0xd1>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movsbl (%rax),%edi
mov    $0x0,%al
call   1030 <putchar@plt>
jmp    11d5 <cut_and_print+0xa5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
movsbl -0xa(%rbp),%eax
cmp    $0x0,%eax
je     1227 <cut_and_print+0xf7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    122f <cut_and_print+0xff>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    118d <cut_and_print+0x5d>
mov    -0x20(%rbp),%rsi
movsbl -0x31(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cut_and_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %edx,0x4(%rsp)
mov    %esi,%ebx
mov    %rdi,%r14
test   %cl,%cl
mov    $0x20,%eax
mov    $0xa,%ecx
cmove  %eax,%ecx
mov    %ecx,(%rsp)
lea    0xe9b(%rip),%rdi
mov    %r8,0x8(%rsp)
mov    %r8,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f8 <cut_and_print+0xc8>
mov    %rax,%r12
mov    %r14,%rbp
jmp    11b2 <cut_and_print+0x82>
xchg   %ax,%ax
add    $0x1,%r12
cmpb   $0x0,0x4(%rsp)
mov    %r12,%rbp
cmove  %r14,%rbp
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
je     11fb <cut_and_print+0xcb>
cmp    %r12,%rbp
jae    1190 <cut_and_print+0x60>
lea    0xe47(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    (%rsp),%edx
mov    0x8(%rsp),%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%r15
sub    %rbp,%r15
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp,%r13,1),%edi
xor    %eax,%eax
call   1030 <putchar@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    11e0 <cut_and_print+0xb0>
jmp    1190 <cut_and_print+0x60>
mov    %r14,%rbp
lea    0xe0a(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    (%rsp),%edx
mov    0x8(%rsp),%rcx
mov    %rbp,%r8
mov    %rsi,%r9
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [7 x i8] c"%s%c%s\00"
@.str.2 = [12 x i8] c"%s%c%s%s%s\0A\00"
define void @cut_and_print(i8* %0, i8 signext %1, i8 signext %2, i8 signext %3, i8* %4, i8* %5) {
%7 = icmp eq i8 %3, 0
%8 = select i1 %7, i32 32, i32 10
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %0)
%10 = sext i8 %1 to i32
%11 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %37, label %13
13: ; preds = %6
%14 = icmp eq i8 %2, 0
br label %15
15: ; preds = %13, %32
%16 = phi i8* [ %11, %13 ], [ %35, %32 ]
%17 = phi i8* [ %0, %13 ], [ %34, %32 ]
%18 = icmp ult i8* %17, %16
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = ptrtoint i8* %17 to i64
%21 = ptrtoint i8* %16 to i64
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %5, i32 %8, i8* %4)
%23 = sub i64 %21, %20
%24 = getelementptr i8, i8* %17, i64 %23
br label %25
25: ; preds = %19, %25
%26 = phi i8* [ %27, %25 ], [ %17, %19 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
%30 = tail call i32 (i32, ...) bitcast (i32 (...)* @putchar to i32 (i32, ...)*)(i32 %29)
%31 = icmp eq i8* %27, %24
br i1 %31, label %32, label %25
32: ; preds = %25, %15
%33 = getelementptr inbounds i8, i8* %16, i64 1
%34 = select i1 %14, i8* %0, i8* %33
%35 = tail call i8* @strchr(i8* dereferenceable(1) %33, i32 %10)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %15
37: ; preds = %32, %6
%38 = phi i8* [ %0, %6 ], [ %34, %32 ]
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %8, i8* %4, i8* %38, i8* %5)
ret void
}