#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*/ fprintf(int /*<<< orphan*/, char *, unsigned char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
void send_stdout(unsigned char *buf) {
  int outlen = buf[0];
  for (size_t i = 0; i < outlen + 1; i++) {
    fprintf(stdout, "%02x ", buf[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<send_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1186 <send_stdout+0x66>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
lea    0xe94(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113e <send_stdout+0x1e>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_stdout>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
movzbl (%rdi),%r13d
mov    0x2ea9(%rip),%r12
mov    (%r12),%edi
lea    0xebe(%rip),%rsi
mov    %r13d,%edx
call   1040 <fprintf@plt>
test   %r13d,%r13d
je     117b <send_stdout+0x5b>
xor    %ebx,%ebx
lea    0xea8(%rip),%r15
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%r14,%rbx,1),%edx
mov    (%r12),%edi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <send_stdout+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [6 x i8] c"%02x \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @send_stdout(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
store i32 %8, i32* %3
store i64 0, i64* %4
br label %9
9: ; preds = %22, %1
%10 = load i64, i64* %4
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = icmp ult i64 %10, %13
br i1 %14, label %15, label %25
15: ; preds = %9
%16 = load i32, i32* @stdout
%17 = load i8*, i8** %2
%18 = load i64, i64* %4
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %20)
br label %22
22: ; preds = %15
%23 = load i64, i64* %4
%24 = add i64 %23, 1
store i64 %24, i64* %4
br label %9
25: ; preds = %9
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

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