#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void print_buf(const char *prefix, char *buf, uint32_t len) {
  uint32_t i;
  if (len > 0) {
    printf("%s |", prefix);
    for (i = 0; i < len; ++i)
      putchar(buf[i]);
    printf("|\n");
  }
}


x86 assembly (clang, -O0):
<print_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    1197 <print_buf+0x77>
mov    -0x8(%rbp),%rsi
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1189 <print_buf+0x69>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1159 <print_buf+0x39>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buf>:
test   %rdx,%rdx
jle    1184 <print_buf+0x54>
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0xeb6(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r14,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1160 <print_buf+0x30>
lea    0xe89(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <puts@plt>
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s |\00"
@.str.1 = [3 x i8] c"|\0A\00"
define void @print_buf(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %11)
store i64 0, i64* %7
br label %13
13: ; preds = %23, %10
%14 = load i64, i64* %7
%15 = load i64, i64* %6
%16 = icmp slt i64 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = load i64, i64* %7
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @putchar(i8 signext %21)
br label %23
23: ; preds = %17
%24 = load i64, i64* %7
%25 = add nsw i64 %24, 1
store i64 %25, i64* %7
br label %13
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %3
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s |\00"
@str = [2 x i8] c"|\00"
define void @print_buf(i8* %0, i8* nocapture %1, i64 %2) {
%4 = icmp sgt i64 %2, 0
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = tail call i32 @putchar(i8 signext %10)
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %2
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %3
ret void
}