#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*/ va_list;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ snprintf(char *, int, char *, char);
void print_hex(char *data, int n) {
  int i;
  char buf[2024];
  va_list args;
  int len = 0;
  int size = 2024;
  for (i = 0; i < n; i++) {
    len += snprintf(buf + len, size - len, "%x ", data[i]);
  }
  printf("%s\n", buf);
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x808(%rbp)
movl   $0x7e8,-0x80c(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11af <print_hex+0x8f>
lea    -0x800(%rbp),%rdi
movslq -0x808(%rbp),%rax
add    %rax,%rdi
mov    -0x80c(%rbp),%esi
sub    -0x808(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe7b(%rip),%rdx
movsbl (%rax,%rcx,1),%ecx
call   1040 <snprintf@plt>
mov    %rax,%rcx
movslq -0x808(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x808(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <print_hex+0x2d>
lea    -0x800(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f0,%rsp
test   %esi,%esi
jle    1178 <print_hex+0x58>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0xebd(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%r13
lea    (%rsp,%r13,1),%rdi
mov    $0x7e8,%esi
sub    %r13d,%esi
movsbl (%r15,%rbx,1),%ecx
mov    %r14,%rdx
call   1040 <snprintf@plt>
add    %r13d,%eax
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <print_hex+0x30>
lea    0xe85(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x7f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%x \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @print_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %8
store i32 2024, i32* %9
store i32 0, i32* %5
br label %10
10: ; preds = %32, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = getelementptr inbounds [2024 x i8], [2024 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %9
%20 = load i32, i32* %8
%21 = sub nsw i32 %19, %20
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i64 @snprintf(i8* %18, i32 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %26)
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %8
br label %32
32: ; preds = %14
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %10
35: ; preds = %10
%36 = getelementptr inbounds [2024 x i8], [2024 x i8]* %6, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%x \00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @print_hex(i8* nocapture %0, i32 %1) {
%3 = alloca [2024 x i8]
%4 = getelementptr inbounds [2024 x i8], [2024 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %19, %8 ]
%10 = phi i32 [ 0, %6 ], [ %18, %8 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [2024 x i8], [2024 x i8]* %3, i64 0, i64 %11
%13 = sub nsw i32 2024, %10
%14 = getelementptr inbounds i8, i8* %0, i64 %9
%15 = load i8, i8* %14
%16 = call i64 @snprintf(i8* %12, i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = trunc i64 %16 to i32
%18 = add i32 %10, %17
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %8, %2
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret void
}