int prn_xprintf(char *buffer) {
  int n;
  bwx_DEBUG(__FUNCTION__);
  n = bwx_CONSOLE_WIDTH();
  if (n > 0) {
    int i;
    i = 0;
    while (*buffer) {
      bwx_PRINT(*buffer);
      buffer++;
      if (*buffer == '\n') {
        i = 0;
      }
      i++;
      if (i >= n) {
        bwx_PRINT('\n');
        i = 0;
      }
    }
  } else {
    while (*buffer) {
      bwx_PRINT(*buffer);
      buffer++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<prn_xprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <bwx_DEBUG@plt>
mov    $0x0,%al
call   1050 <bwx_CONSOLE_WIDTH@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11d5 <prn_xprintf+0xa5>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d0 <prn_xprintf+0xa0>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
mov    $0x0,%al
call   1030 <bwx_PRINT@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11a3 <prn_xprintf+0x73>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11cb <prn_xprintf+0x9b>
mov    $0xa,%edi
mov    $0x0,%al
call   1030 <bwx_PRINT@plt>
movl   $0x0,-0x10(%rbp)
jmp    1165 <prn_xprintf+0x35>
jmp    120b <prn_xprintf+0xdb>
jmp    11da <prn_xprintf+0xaa>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1206 <prn_xprintf+0xd6>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
mov    $0x0,%al
call   1030 <bwx_PRINT@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11da <prn_xprintf+0xaa>
jmp    120b <prn_xprintf+0xdb>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prn_xprintf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <bwx_DEBUG@plt>
xor    %eax,%eax
call   1050 <bwx_CONSOLE_WIDTH@plt>
mov    %eax,%r15d
mov    (%rbx),%al
test   %r15d,%r15d
jle    11a6 <prn_xprintf+0x76>
test   %al,%al
je     11c5 <prn_xprintf+0x95>
add    $0x1,%rbx
mov    $0x1,%r14d
xor    %ebp,%ebp
jmp    1178 <prn_xprintf+0x48>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
test   %al,%al
je     11c5 <prn_xprintf+0x95>
movsbl %al,%edi
xor    %eax,%eax
call   1030 <bwx_PRINT@plt>
movzbl (%rbx),%eax
add    $0x1,%ebp
cmp    $0xa,%al
cmove  %r14d,%ebp
cmp    %r15d,%ebp
jl     1170 <prn_xprintf+0x40>
xor    %ebp,%ebp
mov    $0xa,%edi
xor    %eax,%eax
call   1030 <bwx_PRINT@plt>
movzbl (%rbx),%eax
jmp    1170 <prn_xprintf+0x40>
test   %al,%al
je     11c5 <prn_xprintf+0x95>
add    $0x1,%rbx
xchg   %ax,%ax
movsbl %al,%edi
xor    %eax,%eax
call   1030 <bwx_PRINT@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11b0 <prn_xprintf+0x80>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__FUNCTION__.prn_xprintf = [12 x i8] c"prn_xprintf\00"
define i32 @prn_xprintf(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (i8*, ...) bitcast (i32 (...)* @bwx_DEBUG to i32 (i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__FUNCTION__.prn_xprintf, i64 0, i64 0))
%6 = call i32 (...) @bwx_CONSOLE_WIDTH()
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %1
store i32 0, i32* %4
br label %10
10: ; preds = %34, %9
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i32 (i32, ...) bitcast (i32 (...)* @bwx_PRINT to i32 (i32, ...)*)(i32 %17)
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %14
store i32 0, i32* %4
br label %26
26: ; preds = %25, %14
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = load i32, i32* %3
%31 = icmp sge i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 (i32, ...) bitcast (i32 (...)* @bwx_PRINT to i32 (i32, ...)*)(i32 10)
store i32 0, i32* %4
br label %34
34: ; preds = %32, %26
br label %10
35: ; preds = %10
br label %49
36: ; preds = %1
br label %37
37: ; preds = %41, %36
%38 = load i8*, i8** %2
%39 = load i8, i8* %38
%40 = icmp ne i8 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = load i8*, i8** %2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = call i32 (i32, ...) bitcast (i32 (...)* @bwx_PRINT to i32 (i32, ...)*)(i32 %44)
%46 = load i8*, i8** %2
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %2
br label %37
48: ; preds = %37
br label %49
49: ; preds = %48, %35
ret i32 0
}

LLVM IR (-O2):
@__FUNCTION__.prn_xprintf = [12 x i8] c"prn_xprintf\00"
define i32 @prn_xprintf(i8* nocapture %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @bwx_DEBUG to i32 (i8*, ...)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @__FUNCTION__.prn_xprintf, i64 0, i64 0))
%3 = tail call i32 (...) @bwx_CONSOLE_WIDTH()
%4 = icmp sgt i32 %3, 0
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %4, label %8, label %7
7: ; preds = %1
br i1 %6, label %36, label %28
8: ; preds = %1
br i1 %6, label %36, label %9
9: ; preds = %8, %24
%10 = phi i8 [ %25, %24 ], [ %5, %8 ]
%11 = phi i32 [ %26, %24 ], [ 0, %8 ]
%12 = phi i8* [ %15, %24 ], [ %0, %8 ]
%13 = sext i8 %10 to i32
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @bwx_PRINT to i32 (i32, ...)*)(i32 %13)
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
%18 = add nsw i32 %11, 1
%19 = select i1 %17, i32 1, i32 %18
%20 = icmp slt i32 %19, %3
br i1 %20, label %24, label %21
21: ; preds = %9
%22 = tail call i32 (i32, ...) bitcast (i32 (...)* @bwx_PRINT to i32 (i32, ...)*)(i32 10)
%23 = load i8, i8* %15
br label %24
24: ; preds = %21, %9
%25 = phi i8 [ %23, %21 ], [ %16, %9 ]
%26 = phi i32 [ 0, %21 ], [ %19, %9 ]
%27 = icmp eq i8 %25, 0
br i1 %27, label %36, label %9
28: ; preds = %7, %28
%29 = phi i8 [ %34, %28 ], [ %5, %7 ]
%30 = phi i8* [ %33, %28 ], [ %0, %7 ]
%31 = sext i8 %29 to i32
%32 = tail call i32 (i32, ...) bitcast (i32 (...)* @bwx_PRINT to i32 (i32, ...)*)(i32 %31)
%33 = getelementptr inbounds i8, i8* %30, i64 1
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %28
36: ; preds = %28, %24, %7, %8
ret i32 0
}