#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*/ Dprintf(int, char *, ...);
int sprintf(char *, char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int hexdump(char *data, int data_len, int flag) {
  int i, j;
  char buf[1000];
  char temp[10];
  if (data == NULL) {
    Dprintf(flag, "null\n");
    return -1;
  }
  for (i = 0; i < data_len; i++) {
    j = sprintf(temp, "%x", data[i]);
    if (j < 2) {
      buf[(i % 16) * 3] = '0';
      strcpy(buf + (i % 16) * 3 + 1, temp + j - 1);
    } else
      strcpy(buf + (i % 16) * 3, temp + j - 2);
    strcpy(buf + (i % 16) * 3 + 2, " ");
    if (i % 16 == 15)
      Dprintf(flag, "%s", buf);
  }
  if (i % 16 != 0)
    Dprintf(flag, "%s", buf);
  return 1;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <hexdump+0x3d>
mov    -0x18(%rbp),%edi
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1050 <Dprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12cb <hexdump+0x19b>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1298 <hexdump+0x168>
lea    -0x41a(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe70(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
jge    11fe <hexdump+0xce>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
cltq
movb   $0x30,-0x410(%rbp,%rax,1)
30
lea    -0x410(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
cltq
add    %rax,%rdi
add    $0x1,%rdi
lea    -0x41a(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <strcpy@plt>
jmp    122f <hexdump+0xff>
lea    -0x410(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
cltq
add    %rax,%rdi
lea    -0x41a(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffe,%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
cltq
add    %rax,%rdi
add    $0x2,%rdi
lea    0xdb5(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    1285 <hexdump+0x155>
mov    -0x18(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <Dprintf@plt>
jmp    128a <hexdump+0x15a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1174 <hexdump+0x44>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12c4 <hexdump+0x194>
mov    -0x18(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    0xd4e(%rip),%rsi
mov    $0x0,%al
call   1050 <Dprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
test   %rdi,%rdi
je     121a <hexdump+0xea>
mov    $0x1,%eax
test   %esi,%esi
jle    1254 <hexdump+0x124>
mov    %rdi,%rbx
mov    %edx,0xc(%rsp)
mov    %esi,0x10(%rsp)
mov    %esi,%r15d
lea    0xe9d(%rip),%r14
xor    %r12d,%r12d
jmp    118d <hexdump+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%r15
je     1231 <hexdump+0x101>
movsbl (%rbx,%r12,1),%edx
lea    0x16(%rsp),%rdi
lea    0xe68(%rip),%rsi
call   1040 <sprintf@plt>
mov    %r12d,%r13d
and    $0xf,%r13d
lea    0x0(%r13,%r13,2),%ebp
lea    (%rsp,%rbp,1),%rdi
add    $0x20,%rdi
cmp    $0x1,%eax
jg     11d0 <hexdump+0xa0>
movb   $0x30,(%rdi)
add    $0x1,%rdi
cltq
mov    $0xffffffffffffffff,%rsi
jmp    11d9 <hexdump+0xa9>
xchg   %ax,%ax
mov    %eax,%eax
mov    $0xfffffffffffffffe,%rsi
add    %rsp,%rax
add    $0x16,%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
lea    (%rsp,%rbp,1),%rdi
add    $0x22,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
cmp    $0xf,%r13d
jne    1180 <hexdump+0x50>
mov    0xc(%rsp),%edi
lea    0xe02(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   1050 <Dprintf@plt>
jmp    1180 <hexdump+0x50>
lea    0xddf(%rip),%rsi
mov    %edx,%edi
xor    %eax,%eax
call   1050 <Dprintf@plt>
mov    $0xffffffff,%eax
jmp    1254 <hexdump+0x124>
testb  $0xf,0x10(%rsp)
je     124f <hexdump+0x11f>
lea    0xdcc(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    0xc(%rsp),%edi
xor    %eax,%eax
call   1050 <Dprintf@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"null\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @hexdump(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1000 x i8]
%11 = alloca [10 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* %7
%16 = call i32 (i32, i8*, ...) @Dprintf(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %93
17: ; preds = %3
store i32 0, i32* %8
br label %18
18: ; preds = %81, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %84
22: ; preds = %18
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 2
br i1 %31, label %32, label %51
32: ; preds = %22
%33 = load i32, i32* %8
%34 = srem i32 %33, 16
%35 = mul nsw i32 %34, 3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 %36
store i8 48, i8* %37
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%39 = load i32, i32* %8
%40 = srem i32 %39, 16
%41 = mul nsw i32 %40, 3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %38, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = getelementptr inbounds i8, i8* %48, i64 -1
%50 = call i32 @strcpy(i8* %44, i8* %49)
br label %64
51: ; preds = %22
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%53 = load i32, i32* %8
%54 = srem i32 %53, 16
%55 = mul nsw i32 %54, 3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %52, i64 %56
%58 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = getelementptr inbounds i8, i8* %61, i64 -2
%63 = call i32 @strcpy(i8* %57, i8* %62)
br label %64
64: ; preds = %51, %32
%65 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%66 = load i32, i32* %8
%67 = srem i32 %66, 16
%68 = mul nsw i32 %67, 3
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %65, i64 %69
%71 = getelementptr inbounds i8, i8* %70, i64 2
%72 = call i32 @strcpy(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%73 = load i32, i32* %8
%74 = srem i32 %73, 16
%75 = icmp eq i32 %74, 15
br i1 %75, label %76, label %80
76: ; preds = %64
%77 = load i32, i32* %7
%78 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%79 = call i32 (i32, i8*, ...) @Dprintf(i32 %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %76, %64
br label %81
81: ; preds = %80
%82 = load i32, i32* %8
%83 = add nsw i32 %82, 1
store i32 %83, i32* %8
br label %18
84: ; preds = %18
%85 = load i32, i32* %8
%86 = srem i32 %85, 16
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %84
%89 = load i32, i32* %7
%90 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%91 = call i32 (i32, i8*, ...) @Dprintf(i32 %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %88, %84
store i32 1, i32* %4
br label %93
93: ; preds = %92, %14
%94 = load i32, i32* %4
ret i32 %94
}

LLVM IR (-O2):
@.str = [6 x i8] c"null\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @hexdump(i8* %0, i32 %1, i32 %2) {
%4 = alloca [1000 x i8]
%5 = alloca [10 x i8]
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %0, null
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %52
11: ; preds = %9
%12 = zext i32 %1 to i64
br label %15
13: ; preds = %3
%14 = tail call i32 (i32, i8*, ...) @Dprintf(i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %52
15: ; preds = %11, %44
%16 = phi i64 [ 0, %11 ], [ %45, %44 ]
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %18)
%20 = icmp slt i32 %19, 2
%21 = trunc i64 %16 to i32
%22 = and i32 %21, 15
%23 = mul nuw nsw i32 %22, 3
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %24
br i1 %20, label %26, label %29
26: ; preds = %15
store i8 48, i8* %25
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = sext i32 %19 to i64
br label %31
29: ; preds = %15
%30 = zext i32 %19 to i64
br label %31
31: ; preds = %29, %26
%32 = phi i64 [ %30, %29 ], [ %28, %26 ]
%33 = phi i64 [ -2, %29 ], [ -1, %26 ]
%34 = phi i8* [ %25, %29 ], [ %27, %26 ]
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %32
%36 = getelementptr inbounds i8, i8* %35, i64 %33
%37 = call i32 @strcpy(i8* %34, i8* %36)
%38 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %24
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = call i32 @strcpy(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i32 %22, 15
br i1 %41, label %42, label %44
42: ; preds = %31
%43 = call i32 (i32, i8*, ...) @Dprintf(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %44
44: ; preds = %31, %42
%45 = add nuw nsw i64 %16, 1
%46 = icmp eq i64 %45, %12
br i1 %46, label %47, label %15
47: ; preds = %44
%48 = and i32 %1, 15
%49 = icmp eq i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = call i32 (i32, i8*, ...) @Dprintf(i32 %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
br label %52
52: ; preds = %9, %47, %50, %13
%53 = phi i32 [ -1, %13 ], [ 1, %50 ], [ 1, %47 ], [ 1, %9 ]
ret i32 %53
}