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

/* Variables and functions */
int /*<<< orphan*/ flockfile(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ funlockfile(int /*<<< orphan*/ *);
void fprinthex(FILE *fp, const void *ptr, size_t len) {
  const unsigned char *p = ptr;
  size_t n;
  flockfile(fp);
  for (n = 0; n < len; p++, n++) {
    if (n) {
      if (n % 32 == 0)
        fprintf(fp, "\n");
      else {
        if (n % 8 == 0)
          fprintf(fp, " ");
        fprintf(fp, " ");
      }
    }
    fprintf(fp, "%02x", *p);
  }
  fprintf(fp, "\n------------------------------------------\n");
  funlockfile(fp);
}


x86 assembly (clang, -O0):
<fprinthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <flockfile@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1210 <fprinthex+0xe0>
cmpq   $0x0,-0x28(%rbp)
je     11da <fprinthex+0xaa>
mov    -0x28(%rbp),%rax
and    $0x1f,%rax
cmp    $0x0,%rax
jne    119f <fprinthex+0x6f>
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11d5 <fprinthex+0xa5>
mov    -0x28(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    11c3 <fprinthex+0x93>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11da <fprinthex+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
movzbl (%rax),%edx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115d <fprinthex+0x2d>
mov    -0x8(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <funlockfile@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprinthex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
call   1040 <flockfile@plt>
test   %r14,%r14
je     1189 <fprinthex+0x39>
movzbl (%r15),%edx
lea    0xe87(%rip),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    $0x1,%r14
jne    11b8 <fprinthex+0x68>
lea    0xe75(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <funlockfile@plt>
mov    $0x1,%ebx
lea    0xe3c(%rip),%r12
jmp    11fa <fprinthex+0xaa>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%ebp
mov    %ebp,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
movzbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     1189 <fprinthex+0x39>
test   $0x1f,%bl
je     11d0 <fprinthex+0x80>
mov    $0x20,%ebp
test   $0x7,%bl
jne    11d5 <fprinthex+0x85>
mov    $0x20,%ebp
mov    $0x20,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
jmp    11d5 <fprinthex+0x85>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [45 x i8] c"\0A------------------------------------------\0A\00"
define void @fprinthex(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
%10 = load i32*, i32** %4
%11 = call i32 @flockfile(i32* %10)
store i64 0, i64* %8
br label %12
12: ; preds = %43, %3
%13 = load i64, i64* %8
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %48
16: ; preds = %12
%17 = load i64, i64* %8
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = load i64, i64* %8
%21 = urem i64 %20, 32
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32*, i32** %4
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %36
26: ; preds = %19
%27 = load i64, i64* %8
%28 = urem i64 %27, 8
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32*, i32** %4
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %26
%34 = load i32*, i32** %4
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %33, %23
br label %37
37: ; preds = %36, %16
%38 = load i32*, i32** %4
%39 = load i8*, i8** %7
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %37
%44 = load i8*, i8** %7
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %7
%46 = load i64, i64* %8
%47 = add i64 %46, 1
store i64 %47, i64* %8
br label %12
48: ; preds = %12
%49 = load i32*, i32** %4
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32*, i32** %4
%52 = call i32 @funlockfile(i32* %51)
ret void
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [45 x i8] c"\0A------------------------------------------\0A\00"
define void @fprinthex(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32 @flockfile(i32* %0)
%5 = icmp eq i64 %2, 0
br i1 %5, label %30, label %6
6: ; preds = %3
%7 = load i8, i8* %1
%8 = zext i8 %7 to i32
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp eq i64 %2, 1
br i1 %10, label %30, label %11
11: ; preds = %6, %22
%12 = phi i64 [ %28, %22 ], [ 1, %6 ]
%13 = phi i8* [ %14, %22 ], [ %1, %6 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = and i64 %12, 31
%16 = icmp eq i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %11
%18 = and i64 %12, 7
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @fputc(i32 32, i32* %0)
br label %22
22: ; preds = %17, %20, %11
%23 = phi i32 [ 10, %11 ], [ 32, %20 ], [ 32, %17 ]
%24 = tail call i32 @fputc(i32 %23, i32* %0)
%25 = load i8, i8* %14
%26 = zext i8 %25 to i32
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = add nuw i64 %12, 1
%29 = icmp eq i64 %28, %2
br i1 %29, label %30, label %11
30: ; preds = %22, %6, %3
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i64 44, i64 1, i32* %0)
%32 = tail call i32 @funlockfile(i32* %0)
ret void
}