#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ logmessage(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void printline(char *msg) {
  char buf[4096 + 4];
  register char *msg_pt, *buf_pt;
  register unsigned char c;
  msg_pt = msg;
  memset(buf, 0, sizeof(buf));
  buf_pt = buf;
  while ((c = *msg_pt++) && buf_pt < &buf[sizeof(buf) - 4]) {
    if (c == '\0') {
      break;
    } else if (c <= 0x1F || c == 0x7F) {
      *buf_pt++ = ' ';
    } else {
      *buf_pt++ = c;
    }
  }
  *buf_pt++ = '\n';
  *buf_pt = '\0';
  logmessage(buf);
}


x86 assembly (clang, -O0):
<printline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1004,%edx
call   1030 <memset@plt>
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1020(%rbp)
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1018(%rbp)
mov    (%rax),%al
mov    %al,-0x1021(%rbp)
movzbl %al,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1022(%rbp)
je     11ad <printline+0x8d>
mov    -0x1020(%rbp),%rax
lea    -0x1010(%rbp),%rcx
add    $0x1000,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x1022(%rbp)
mov    -0x1022(%rbp),%al
test   $0x1,%al
jne    11c0 <printline+0xa0>
jmp    1239 <printline+0x119>
movzbl -0x1021(%rbp),%eax
cmp    $0x0,%eax
jne    11d5 <printline+0xb5>
jmp    1239 <printline+0x119>
movzbl -0x1021(%rbp),%eax
cmp    $0x1f,%eax
jle    11f5 <printline+0xd5>
movzbl -0x1021(%rbp),%eax
cmp    $0x7f,%eax
jne    1212 <printline+0xf2>
mov    -0x1020(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1020(%rbp)
movb   $0x20,(%rax)
jmp    122f <printline+0x10f>
mov    -0x1021(%rbp),%cl
mov    -0x1020(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x1020(%rbp)
mov    %cl,(%rax)
jmp    1234 <printline+0x114>
jmp    115b <printline+0x3b>
mov    -0x1020(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1020(%rbp)
movb   $0xa,(%rax)
mov    -0x1020(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1010(%rbp),%rdi
call   1040 <logmessage@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printline>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1004,%edx
call   1030 <memset@plt>
mov    (%r14),%dl
test   %dl,%dl
je     1189 <printline+0x69>
lea    0x1000(%rsp),%rax
mov    %rsp,%rbx
add    $0x1,%r14
mov    $0x20,%ecx
nopw   0x0(%rax,%rax,1)
cmp    $0x7f,%dl
movzbl %dl,%edx
mov    %edx,%esi
cmove  %ecx,%esi
cmp    $0x20,%dl
cmovb  %ecx,%esi
mov    %sil,(%rbx)
add    $0x1,%rbx
movzbl (%r14),%edx
test   %dl,%dl
je     1189 <printline+0x69>
add    $0x1,%r14
cmp    %rax,%rbx
jb     1160 <printline+0x40>
movw   $0xa,(%rbx)
mov    %rsp,%rdi
call   1040 <logmessage@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @printline(i8* %0) {
%2 = alloca i8*
%3 = alloca [4100 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %2
%7 = load i8*, i8** %2
store i8* %7, i8** %4
%8 = getelementptr inbounds [4100 x i8], [4100 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 4100)
%10 = getelementptr inbounds [4100 x i8], [4100 x i8]* %3, i64 0, i64 0
store i8* %10, i8** %5
br label %11
11: ; preds = %44, %1
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
%14 = load i8, i8* %12
store i8 %14, i8* %6
%15 = zext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i8*, i8** %5
%19 = getelementptr inbounds [4100 x i8], [4100 x i8]* %3, i64 0, i64 4096
%20 = icmp ult i8* %18, %19
br label %21
21: ; preds = %17, %11
%22 = phi i1 [ false, %11 ], [ %20, %17 ]
br i1 %22, label %23, label %45
23: ; preds = %21
%24 = load i8, i8* %6
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
br label %45
28: ; preds = %23
%29 = load i8, i8* %6
%30 = zext i8 %29 to i32
%31 = icmp sle i32 %30, 31
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8, i8* %6
%34 = zext i8 %33 to i32
%35 = icmp eq i32 %34, 127
br i1 %35, label %36, label %39
36: ; preds = %32, %28
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
store i8 32, i8* %37
br label %43
39: ; preds = %32
%40 = load i8, i8* %6
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
store i8 %40, i8* %41
br label %43
43: ; preds = %39, %36
br label %44
44: ; preds = %43
br label %11
45: ; preds = %27, %21
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %5
store i8 10, i8* %46
%48 = load i8*, i8** %5
store i8 0, i8* %48
%49 = getelementptr inbounds [4100 x i8], [4100 x i8]* %3, i64 0, i64 0
%50 = call i32 @logmessage(i8* %49)
ret void
}

LLVM IR (-O2):
define void @printline(i8* nocapture %0) {
%2 = alloca [4100 x i8]
%3 = getelementptr inbounds [4100 x i8], [4100 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 4100)
%5 = getelementptr inbounds [4100 x i8], [4100 x i8]* %2, i64 0, i64 4096
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %1, %8
%9 = phi i8 [ %18, %8 ], [ %6, %1 ]
%10 = phi i8* [ %12, %8 ], [ %0, %1 ]
%11 = phi i8* [ %17, %8 ], [ %3, %1 ]
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = icmp ult i8 %9, 32
%14 = icmp eq i8 %9, 127
%15 = or i1 %13, %14
%16 = select i1 %15, i8 32, i8 %9
%17 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %16, i8* %11
%18 = load i8, i8* %12
%19 = icmp uge i8* %17, %5
%20 = icmp eq i8 %18, 0
%21 = select i1 %20, i1 true, i1 %19
br i1 %21, label %22, label %8
22: ; preds = %8, %1
%23 = phi i8* [ %3, %1 ], [ %17, %8 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
store i8 10, i8* %23
store i8 0, i8* %24
%25 = call i32 @logmessage(i8* %3)
ret void
}