#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*/ strncpy(char *, char *, int);
void log_prepare(char *buffer, char *value) {
  char *p;
  if (!value)
    value = "<None Specified>";
  strncpy(buffer, value, 255);
  buffer[255] = 0;
  for (p = buffer; *p; p++)
    if (*p >= 0 && *p < 32)
      *p = ' ';
}


x86 assembly (clang, -O0):
<log_prepare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1136 <log_prepare+0x26>
lea    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0xff(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a5 <log_prepare+0x95>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jl     118f <log_prepare+0x7f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    118f <log_prepare+0x7f>
mov    -0x18(%rbp),%rax
movb   $0x20,(%rax)
jmp    1194 <log_prepare+0x84>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115b <log_prepare+0x4b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_prepare>:
push   %rbx
mov    %rdi,%rbx
test   %rsi,%rsi
lea    0xee2(%rip),%rax
cmove  %rax,%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xff(%rbx)
mov    (%rbx),%al
test   %al,%al
je     1155 <log_prepare+0x45>
add    $0x1,%rbx
jmp    114b <log_prepare+0x3b>
nop
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1155 <log_prepare+0x45>
cmp    $0x1f,%al
ja     1140 <log_prepare+0x30>
movb   $0x20,-0x1(%rbx)
jmp    1140 <log_prepare+0x30>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"<None Specified>\00"
define void @log_prepare(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %4
br label %9
9: ; preds = %8, %2
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 255)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 255
store i8 0, i8* %14
%15 = load i8*, i8** %3
store i8* %15, i8** %5
br label %16
16: ; preds = %33, %9
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp slt i32 %28, 32
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = load i8*, i8** %5
store i8 32, i8* %31
br label %32
32: ; preds = %30, %25, %20
br label %33
33: ; preds = %32
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %16
36: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"<None Specified>\00"
define void @log_prepare(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
%4 = select i1 %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %1
%5 = tail call i32 @strncpy(i8* %0, i8* %4, i32 255)
%6 = getelementptr inbounds i8, i8* %0, i64 255
store i8 0, i8* %6
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %2, %14
%10 = phi i8 [ %16, %14 ], [ %7, %2 ]
%11 = phi i8* [ %15, %14 ], [ %0, %2 ]
%12 = icmp ult i8 %10, 32
br i1 %12, label %13, label %14
13: ; preds = %9
store i8 32, i8* %11
br label %14
14: ; preds = %9, %13
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %9
18: ; preds = %14, %2
ret void
}