#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 */
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int dump_buf(FILE *fp, const unsigned char *buf, int len, const char *desc) {
  struct timeval tv;
  if (desc)
    fprintf(fp, "%s:\n", desc);
  gettimeofday(&tv, NULL);
  fprintf(fp, "++ %ld.%06ld ++ ---------------------------\n", tv.tv_sec,
          tv.tv_usec);
  for (int i = 0; i < len; i++) {
    fprintf(fp, "0x%02x ", (unsigned char)buf[i]);
    if ((i + 1) % 16 == 0)
      fprintf(fp, "\n");
  }
  fprintf(fp, "\n--------------------------------------------------------\n");
  return len;
}


x86 assembly (clang, -O0):
<dump_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1158 <dump_buf+0x38>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xeaf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ea <dump_buf+0xca>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe8b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d7 <dump_buf+0xb7>
mov    -0x8(%rbp),%rdi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11dc <dump_buf+0xbc>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1184 <dump_buf+0x64>
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r13
test   %rcx,%rcx
je     116d <dump_buf+0x2d>
lea    0xea0(%rip),%rsi
mov    %r13,%rdi
mov    %rcx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
lea    0xe80(%rip),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r14d,%r14d
jle    11e9 <dump_buf+0xa9>
mov    %r14d,%ebp
neg    %rbp
mov    $0x1,%ebx
lea    0xe8c(%rip),%r15
jmp    11c2 <dump_buf+0x82>
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     11e9 <dump_buf+0xa9>
movzbl -0x1(%r12,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   $0xf,%bl
jne    11b0 <dump_buf+0x70>
mov    $0xa,%edi
mov    %r13,%rsi
call   1040 <fputc@plt>
jmp    11b0 <dump_buf+0x70>
lea    0xe4a(%rip),%rdi
mov    $0x3a,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1060 <fwrite@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [45 x i8] c"++ %ld.%06ld ++ ---------------------------\0A\00"
@.str.2 = [8 x i8] c"0x%02x \00"
@.str.4 = [59 x i8] c"\0A--------------------------------------------------------\0A\00"
define i32 @dump_buf(i32* nocapture %0, i8* nocapture %1, i32 returned %2, i8* %3) {
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %5 to i8*
%7 = icmp eq i8* %3, null
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %10
10: ; preds = %8, %4
%11 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15)
%17 = icmp sgt i32 %2, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = zext i32 %2 to i64
br label %22
20: ; preds = %33, %10
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i64 58, i64 1, i32* %0)
ret i32 %2
22: ; preds = %18, %33
%23 = phi i64 [ 0, %18 ], [ %28, %33 ]
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i64 %23, 1
%29 = and i64 %28, 15
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = tail call i32 @fputc(i32 10, i32* %0)
br label %33
33: ; preds = %22, %31
%34 = icmp eq i64 %28, %19
br i1 %34, label %20, label %22
}