#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*/ printf(char *, ...);
void print_hex_string(char *buf, int len) {
  int i;
  if (len == 0) {
    printf("<empty string>");
    return;
  }
  if (len >= 40) {
    for (i = 0; i < 10; i++)
      printf("%02x", *((unsigned char *)buf + i));
    printf(" ... ");
    for (i = len - 10; i < len; i++)
      printf("%02x", *((unsigned char *)buf + i));
    printf(" [%d bytes]", len);
    return;
  }
  for (i = 0; i < len; i++)
    printf("%02x", *((unsigned char *)buf + i));
}


x86 assembly (clang, -O0):
<print_hex_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    113c <print_hex_string+0x2c>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121b <print_hex_string+0x10b>
cmpl   $0x28,-0xc(%rbp)
jl     11e0 <print_hex_string+0xd0>
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    117f <print_hex_string+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <print_hex_string+0x3d>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ca <print_hex_string+0xba>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1196 <print_hex_string+0x86>
mov    -0xc(%rbp),%esi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121b <print_hex_string+0x10b>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121b <print_hex_string+0x10b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e7 <print_hex_string+0xd7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
je     1222 <print_hex_string+0x112>
mov    %esi,%r14d
mov    %rdi,%r12
cmp    $0x28,%esi
jl     1239 <print_hex_string+0x129>
movzbl (%r12),%esi
lea    0xed3(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x1(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x2(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x3(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x4(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x5(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x6(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x7(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x8(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movzbl 0x9(%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0xa(%r14),%ebx
mov    %r14d,%r13d
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
jb     11f0 <print_hex_string+0xe0>
lea    0xe0b(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
test   %r14d,%r14d
jle    1268 <print_hex_string+0x158>
mov    %r14d,%r15d
lea    0xdc7(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1250 <print_hex_string+0x140>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"<empty string>\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [6 x i8] c" ... \00"
@.str.3 = [12 x i8] c" [%d bytes]\00"
define void @print_hex_string(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %66
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 40
br i1 %12, label %13, label %50
13: ; preds = %10
store i32 0, i32* %5
br label %14
14: ; preds = %25, %13
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 10
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %17
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %14
28: ; preds = %14
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 10
store i32 %31, i32* %5
br label %32
32: ; preds = %44, %28
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %47
36: ; preds = %32
%37 = load i8*, i8** %3
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %36
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %32
47: ; preds = %32
%48 = load i32, i32* %4
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %48)
br label %66
50: ; preds = %10
store i32 0, i32* %5
br label %51
51: ; preds = %63, %50
%52 = load i32, i32* %5
%53 = load i32, i32* %4
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %66
55: ; preds = %51
%56 = load i8*, i8** %3
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %55
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %51
66: ; preds = %8, %47, %51
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"<empty string>\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [6 x i8] c" ... \00"
@.str.3 = [12 x i8] c" [%d bytes]\00"
define void @print_hex_string(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %74
6: ; preds = %2
%7 = icmp sgt i32 %1, 39
br i1 %7, label %8, label %52
8: ; preds = %6
%9 = load i8, i8* %0
%10 = zext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i8, i8* %0, i64 2
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds i8, i8* %0, i64 3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds i8, i8* %0, i64 4
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds i8, i8* %0, i64 5
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds i8, i8* %0, i64 6
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds i8, i8* %0, i64 7
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds i8, i8* %0, i64 8
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds i8, i8* %0, i64 9
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%49 = add nsw i32 %1, -10
%50 = zext i32 %49 to i64
%51 = zext i32 %1 to i64
br label %56
52: ; preds = %6
%53 = icmp sgt i32 %1, 0
br i1 %53, label %54, label %74
54: ; preds = %52
%55 = zext i32 %1 to i64
br label %66
56: ; preds = %8, %56
%57 = phi i64 [ %50, %8 ], [ %62, %56 ]
%58 = getelementptr inbounds i8, i8* %0, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = add nuw nsw i64 %57, 1
%63 = icmp ult i64 %62, %51
br i1 %63, label %56, label %64
64: ; preds = %56
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %1)
br label %74
66: ; preds = %54, %66
%67 = phi i64 [ 0, %54 ], [ %72, %66 ]
%68 = getelementptr inbounds i8, i8* %0, i64 %67
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %70)
%72 = add nuw nsw i64 %67, 1
%73 = icmp eq i64 %72, %55
br i1 %73, label %74, label %66
74: ; preds = %66, %52, %64, %4
ret void
}