#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*/ log_(char *, char const *);
int /*<<< orphan*/ memcpy(char *, char *, int);
void print_buf(const char *pref, char *buf, int len) {
  char buf2[1024];
  memcpy(buf2, buf, len);
  buf2[len] = 0;
  int i;
  for (i = 0; i < len; i++) {
    if (buf2[i] == '\n')
      buf2[i] = '^';
    else if (buf2[i] == '\r')
      buf2[i] = '~';
  }
  log_("%s", pref);
  log_("'%s'\n", buf2);
}


x86 assembly (clang, -O0):
<print_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <memcpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11df <print_buf+0xbf>
movslq -0x424(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    119a <print_buf+0x7a>
movslq -0x424(%rbp),%rax
movb   $0x5e,-0x420(%rbp,%rax,1)
5e
jmp    11c6 <print_buf+0xa6>
movslq -0x424(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
jne    11c1 <print_buf+0xa1>
movslq -0x424(%rbp),%rax
movb   $0x7e,-0x420(%rbp,%rax,1)
7e
jmp    11c6 <print_buf+0xa6>
jmp    11cb <print_buf+0xab>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    115f <print_buf+0x3f>
mov    -0x8(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1040 <log_@plt>
lea    -0x420(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1040 <log_@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edx,%ebp
mov    %rdi,%r14
mov    %rsp,%rdi
call   1030 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
test   %eax,%eax
jle    11bd <print_buf+0x9d>
mov    %ebp,%ecx
cmp    $0x1,%ebp
jne    1162 <print_buf+0x42>
xor    %eax,%eax
test   $0x1,%cl
je     11bd <print_buf+0x9d>
mov    (%rsp,%rax,1),%cl
cmp    $0xa,%cl
je     11b8 <print_buf+0x98>
cmp    $0xd,%cl
jne    11bd <print_buf+0x9d>
mov    $0x7e,%cl
jmp    11ba <print_buf+0x9a>
mov    %ecx,%edx
and    $0xfffffffe,%edx
xor    %eax,%eax
jmp    117f <print_buf+0x5f>
nopl   0x0(%rax,%rax,1)
mov    $0x5e,%bl
mov    %bl,0x1(%rsp,%rax,1)
add    $0x2,%rax
cmp    %rax,%rdx
je     114c <print_buf+0x2c>
movzbl (%rsp,%rax,1),%ebx
cmp    $0xa,%bl
je     11a0 <print_buf+0x80>
cmp    $0xd,%bl
jne    11a5 <print_buf+0x85>
mov    $0x7e,%bl
jmp    11a2 <print_buf+0x82>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x5e,%bl
mov    %bl,(%rsp,%rax,1)
movzbl 0x1(%rsp,%rax,1),%ebx
cmp    $0xa,%bl
je     1170 <print_buf+0x50>
cmp    $0xd,%bl
jne    1176 <print_buf+0x56>
mov    $0x7e,%bl
jmp    1172 <print_buf+0x52>
mov    $0x5e,%cl
mov    %cl,(%rsp,%rax,1)
lea    0xe3c(%rip),%rdi
mov    %r14,%rsi
call   1040 <log_@plt>
lea    0xe30(%rip),%rdi
mov    %rsp,%rsi
call   1040 <log_@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"'%s'\0A\00"
define void @print_buf(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @memcpy(i8* %5, i8* %1, i32 %2)
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %7
store i8 0, i8* %8
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %44
10: ; preds = %3
%11 = zext i32 %2 to i64
%12 = and i64 %11, 1
%13 = icmp eq i32 %2, 1
br i1 %13, label %35, label %14
14: ; preds = %10
%15 = and i64 %11, 4294967294
br label %16
16: ; preds = %31, %14
%17 = phi i64 [ 0, %14 ], [ %32, %31 ]
%18 = phi i64 [ 0, %14 ], [ %33, %31 ]
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %17
%20 = load i8, i8* %19
switch i8 %20, label %24 [
i8 10, label %22
i8 13, label %21
]
21: ; preds = %16
br label %22
22: ; preds = %16, %21
%23 = phi i8 [ 126, %21 ], [ 94, %16 ]
store i8 %23, i8* %19
br label %24
24: ; preds = %22, %16
%25 = or i64 %17, 1
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %25
%27 = load i8, i8* %26
switch i8 %27, label %31 [
i8 10, label %29
i8 13, label %28
]
28: ; preds = %24
br label %29
29: ; preds = %28, %24
%30 = phi i8 [ 126, %28 ], [ 94, %24 ]
store i8 %30, i8* %26
br label %31
31: ; preds = %29, %24
%32 = add nuw nsw i64 %17, 2
%33 = add i64 %18, 2
%34 = icmp eq i64 %33, %15
br i1 %34, label %35, label %16
35: ; preds = %31, %10
%36 = phi i64 [ 0, %10 ], [ %32, %31 ]
%37 = icmp eq i64 %12, 0
br i1 %37, label %44, label %38
38: ; preds = %35
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %36
%40 = load i8, i8* %39
switch i8 %40, label %44 [
i8 10, label %42
i8 13, label %41
]
41: ; preds = %38
br label %42
42: ; preds = %41, %38
%43 = phi i8 [ 126, %41 ], [ 94, %38 ]
store i8 %43, i8* %39
br label %44
44: ; preds = %35, %42, %38, %3
%45 = call i32 @log_(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%46 = call i32 @log_(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret void
}