#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 trace_seq {
  int dummy;
};

/* Variables and functions */
int trace_seq_printf(struct trace_seq *, char *, char *, unsigned char const);
int /*<<< orphan*/ trace_seq_putc(struct trace_seq *, char);
int trace_seq_puts(struct trace_seq *, char *);
int blk_log_dump_pdu(struct trace_seq *s, const unsigned char *pdu_buf,
                     int pdu_len) {
  int i, end, ret;
  if (!pdu_len)
    return 1;
  for (end = pdu_len - 1; end >= 0; end--)
    if (pdu_buf[end])
      break;
  end++;
  if (!trace_seq_putc(s, '('))
    return 0;
  for (i = 0; i < pdu_len; i++) {
    ret = trace_seq_printf(s, "%s%02x", i == 0 ? "" : " ", pdu_buf[i]);
    if (!ret)
      return ret;
    if (i == end && end != pdu_len - 1)
      return trace_seq_puts(s, " ..) ");
  }
  return trace_seq_puts(s, ") ");
}


x86 assembly (clang, -O0):
<blk_log_dump_pdu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1159 <blk_log_dump_pdu+0x29>
movl   $0x1,-0x4(%rbp)
jmp    127c <blk_log_dump_pdu+0x14c>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1196 <blk_log_dump_pdu+0x66>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1183 <blk_log_dump_pdu+0x53>
jmp    1196 <blk_log_dump_pdu+0x66>
jmp    1188 <blk_log_dump_pdu+0x58>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <blk_log_dump_pdu+0x32>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x28,%esi
call   1050 <trace_seq_putc@plt>
cmp    $0x0,%eax
jne    11c2 <blk_log_dump_pdu+0x92>
movl   $0x0,-0x4(%rbp)
jmp    127c <blk_log_dump_pdu+0x14c>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1269 <blk_log_dump_pdu+0x139>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%ecx
lea    0xe28(%rip),%rdx
lea    0xe22(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xe00(%rip),%rsi
movzbl (%rax,%rcx,1),%ecx
call   1030 <trace_seq_printf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1221 <blk_log_dump_pdu+0xf1>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <blk_log_dump_pdu+0x14c>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1256 <blk_log_dump_pdu+0x126>
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1256 <blk_log_dump_pdu+0x126>
mov    -0x10(%rbp),%rdi
lea    0xdbe(%rip),%rsi
call   1040 <trace_seq_puts@plt>
mov    %eax,-0x4(%rbp)
jmp    127c <blk_log_dump_pdu+0x14c>
jmp    125b <blk_log_dump_pdu+0x12b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c9 <blk_log_dump_pdu+0x99>
mov    -0x10(%rbp),%rdi
lea    0xd96(%rip),%rsi
call   1040 <trace_seq_puts@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blk_log_dump_pdu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     11fb <blk_log_dump_pdu+0xcb>
mov    %rdi,%r14
jle    1202 <blk_log_dump_pdu+0xd2>
mov    %edx,%r12d
mov    %rsi,%rbx
lea    -0x1(%r12),%eax
mov    %eax,0x4(%rsp)
mov    %edx,%eax
nopl   (%rax)
lea    -0x1(%rax),%r15d
cmpb   $0x0,(%rbx,%r15,1)
jne    1176 <blk_log_dump_pdu+0x46>
add    $0xffffffff,%eax
jg     1160 <blk_log_dump_pdu+0x30>
mov    $0xffffffff,%r15d
mov    %r14,%rdi
mov    $0x28,%esi
call   1050 <trace_seq_putc@plt>
test   %eax,%eax
je     1230 <blk_log_dump_pdu+0x100>
lea    0xe78(%rip),%rsi
test   %r12d,%r12d
jle    121a <blk_log_dump_pdu+0xea>
add    $0x1,%r15d
mov    %r15d,%ebp
mov    %r12d,%r13d
xor    %r12d,%r12d
jmp    11b9 <blk_log_dump_pdu+0x89>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    %r12,%r13
je     1213 <blk_log_dump_pdu+0xe3>
test   %r12,%r12
lea    0xe48(%rip),%rdx
lea    0xe42(%rip),%rax
cmove  %rax,%rdx
movzbl (%rbx,%r12,1),%ecx
mov    %r14,%rdi
lea    0xe23(%rip),%rsi
call   1030 <trace_seq_printf@plt>
test   %eax,%eax
je     1230 <blk_log_dump_pdu+0x100>
cmp    %r12,%rbp
jne    11b0 <blk_log_dump_pdu+0x80>
cmp    0x4(%rsp),%r15d
je     11b0 <blk_log_dump_pdu+0x80>
lea    0xe0e(%rip),%rsi
jmp    121a <blk_log_dump_pdu+0xea>
mov    $0x1,%eax
jmp    1232 <blk_log_dump_pdu+0x102>
mov    %r14,%rdi
mov    $0x28,%esi
call   1050 <trace_seq_putc@plt>
test   %eax,%eax
je     1230 <blk_log_dump_pdu+0x100>
lea    0xdf0(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <trace_seq_puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
@.str = [7 x i8] c"%s%02x\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
@.str.3 = [6 x i8] c" ..) \00"
@.str.4 = [3 x i8] c") \00"
define i32 @blk_log_dump_pdu(%struct.trace_seq* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.trace_seq*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.trace_seq* %0, %struct.trace_seq** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 1, i32* %4
br label %79
14: ; preds = %3
%15 = load i32, i32* %7
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %9
br label %17
17: ; preds = %29, %14
%18 = load i32, i32* %9
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
br label %32
28: ; preds = %20
br label %29
29: ; preds = %28
%30 = load i32, i32* %9
%31 = add nsw i32 %30, -1
store i32 %31, i32* %9
br label %17
32: ; preds = %27, %17
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
%35 = load %struct.trace_seq*, %struct.trace_seq** %5
%36 = call i32 @trace_seq_putc(%struct.trace_seq* %35, i8 signext 40)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32
store i32 0, i32* %4
br label %79
39: ; preds = %32
store i32 0, i32* %8
br label %40
40: ; preds = %73, %39
%41 = load i32, i32* %8
%42 = load i32, i32* %7
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %76
44: ; preds = %40
%45 = load %struct.trace_seq*, %struct.trace_seq** %5
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%50 = load i8*, i8** %6
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @trace_seq_printf(%struct.trace_seq* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %49, i8 zeroext %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp ne i32 %56, 0
br i1 %57, label %60, label %58
58: ; preds = %44
%59 = load i32, i32* %10
store i32 %59, i32* %4
br label %79
60: ; preds = %44
%61 = load i32, i32* %8
%62 = load i32, i32* %9
%63 = icmp eq i32 %61, %62
br i1 %63, label %64, label %72
64: ; preds = %60
%65 = load i32, i32* %9
%66 = load i32, i32* %7
%67 = sub nsw i32 %66, 1
%68 = icmp ne i32 %65, %67
br i1 %68, label %69, label %72
69: ; preds = %64
%70 = load %struct.trace_seq*, %struct.trace_seq** %5
%71 = call i32 @trace_seq_puts(%struct.trace_seq* %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 %71, i32* %4
br label %79
72: ; preds = %64, %60
br label %73
73: ; preds = %72
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
br label %40
76: ; preds = %40
%77 = load %struct.trace_seq*, %struct.trace_seq** %5
%78 = call i32 @trace_seq_puts(%struct.trace_seq* %77, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %78, i32* %4
br label %79
79: ; preds = %76, %69, %58, %38, %13
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
@.str = [7 x i8] c"%s%02x\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
@.str.3 = [6 x i8] c" ..) \00"
@.str.4 = [3 x i8] c") \00"
define i32 @blk_log_dump_pdu(%struct.trace_seq* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %47, label %5
5: ; preds = %3
%6 = add nsw i32 %2, -1
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %22
8: ; preds = %5, %14
%9 = phi i32 [ %15, %14 ], [ %6, %5 ]
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = add nsw i32 %9, -1
%16 = icmp sgt i32 %9, 0
br i1 %16, label %8, label %17
17: ; preds = %14, %8
%18 = phi i32 [ -1, %14 ], [ %9, %8 ]
%19 = add nsw i32 %18, 1
%20 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 40)
%21 = icmp eq i32 %20, 0
br i1 %21, label %47, label %25
22: ; preds = %5
%23 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 40)
%24 = icmp eq i32 %23, 0
br i1 %24, label %47, label %44
25: ; preds = %17
br i1 %7, label %26, label %44
26: ; preds = %25
%27 = icmp eq i32 %19, %6
%28 = zext i32 %19 to i64
%29 = zext i32 %2 to i64
br label %32
30: ; preds = %40
%31 = icmp eq i64 %43, %29
br i1 %31, label %44, label %32
32: ; preds = %26, %30
%33 = phi i64 [ 0, %26 ], [ %43, %30 ]
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%36 = getelementptr inbounds i8, i8* %1, i64 %33
%37 = load i8, i8* %36
%38 = tail call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %35, i8 zeroext %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %47, label %40
40: ; preds = %32
%41 = icmp ne i64 %33, %28
%42 = select i1 %41, i1 true, i1 %27
%43 = add nuw nsw i64 %33, 1
br i1 %42, label %30, label %44
44: ; preds = %30, %40, %25, %22
%45 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %22 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %25 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %40 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %30 ]
%46 = tail call i32 @trace_seq_puts(%struct.trace_seq* %0, i8* %45)
br label %47
47: ; preds = %32, %44, %22, %17, %3
%48 = phi i32 [ 1, %3 ], [ 0, %17 ], [ 0, %22 ], [ %46, %44 ], [ 0, %32 ]
ret i32 %48
}