#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*/ tmp;
struct ss7 {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ ss7_message(struct ss7 *, char *, char *);
void ss7_dump_buf(struct ss7 *ss7, int tabs, unsigned char *buf, int len) {
  int i, j = 0;
  char tmp[1024];
  for (i = 0; i < tabs; i++) {
    snprintf(&tmp[i], sizeof(tmp) - i, "\t");
  }
  snprintf(&tmp[i], sizeof(tmp) - i, "[ ");
  j = i + 2;
  for (i = 0; i < len; i++) {
    snprintf(&tmp[3 * i] + j, sizeof(tmp) - 3 * i - j, "%02x ", buf[i]);
  }
  ss7_message(ss7, "%s]\n", tmp);
}


x86 assembly (clang, -O0):
<ss7_dump_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118b <ss7_dump_buf+0x6b>
movslq -0x20(%rbp),%rax
lea    -0x430(%rbp),%rdi
add    %rax,%rdi
movslq -0x20(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe8a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1147 <ss7_dump_buf+0x27>
movslq -0x20(%rbp),%rax
lea    -0x430(%rbp),%rdi
add    %rax,%rdi
movslq -0x20(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%esi
lea    0xe54(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1228 <ss7_dump_buf+0x108>
imul   $0x3,-0x20(%rbp),%eax
cltq
lea    -0x430(%rbp),%rdi
add    %rax,%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
imul   $0x3,-0x20(%rbp),%eax
movslq %eax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
movslq -0x24(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
lea    0xdf2(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c5 <ss7_dump_buf+0xa5>
mov    -0x8(%rbp),%rdi
lea    -0x430(%rbp),%rdx
lea    0xdd1(%rip),%rsi
call   1040 <ss7_message@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ss7_dump_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %ecx,%ebp
mov    %rdx,%r13
mov    %rdi,0x8(%rsp)
test   %esi,%esi
jle    1188 <ss7_dump_buf+0x68>
mov    %esi,%r15d
mov    %ebp,0x4(%rsp)
mov    %esi,%ebp
neg    %rbp
lea    0x10(%rsp),%rbx
lea    0xea9(%rip),%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
lea    0x400(%r12),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <snprintf@plt>
add    $0xffffffffffffffff,%r12
add    $0x1,%rbx
cmp    %r12,%rbp
jne    1160 <ss7_dump_buf+0x40>
mov    0x4(%rsp),%ebp
jmp    118b <ss7_dump_buf+0x6b>
xor    %r15d,%r15d
mov    %r15d,%ebx
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
mov    $0x400,%esi
sub    %r15d,%esi
lea    0xe5d(%rip),%rdx
xor    %eax,%eax
call   1030 <snprintf@plt>
test   %ebp,%ebp
jle    1207 <ss7_dump_buf+0xe7>
mov    %ebp,%r14d
mov    $0x3fe,%r12d
sub    %r15d,%r12d
lea    0x10(%rsp),%rax
add    %rax,%rbx
add    $0x2,%rbx
lea    0xe36(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbp,1),%ecx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <snprintf@plt>
add    $0x1,%rbp
add    $0xfffffffd,%r12d
add    $0x3,%rbx
cmp    %rbp,%r14
jne    11e0 <ss7_dump_buf+0xc0>
lea    0xdfd(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    0x8(%rsp),%rdi
call   1040 <ss7_message@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.ss7 = type { i32 }
@.str = [2 x i8] c"\09\00"
@.str.1 = [3 x i8] c"[ \00"
@.str.2 = [6 x i8] c"%02x \00"
@.str.3 = [5 x i8] c"%s]\0A\00"
define void @ss7_dump_buf(%struct.ss7* %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %18
8: ; preds = %4
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %11
%13 = trunc i64 %11 to i32
%14 = sub i32 1024, %13
%15 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10, %4
%19 = phi i32 [ 0, %4 ], [ %1, %10 ]
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %20
%22 = sub nsw i32 1024, %19
%23 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp sgt i32 %3, 0
br i1 %24, label %25, label %43
25: ; preds = %18
%26 = add nuw nsw i32 %19, 2
%27 = zext i32 %26 to i64
%28 = zext i32 %3 to i64
br label %29
29: ; preds = %25, %29
%30 = phi i64 [ 0, %25 ], [ %41, %29 ]
%31 = mul nuw nsw i64 %30, 3
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %31
%33 = getelementptr inbounds i8, i8* %32, i64 %27
%34 = trunc i64 %31 to i32
%35 = add i32 %19, %34
%36 = sub i32 1022, %35
%37 = getelementptr inbounds i8, i8* %2, i64 %30
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, i32 %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = add nuw nsw i64 %30, 1
%42 = icmp eq i64 %41, %28
br i1 %42, label %43, label %29
43: ; preds = %29, %18
%44 = call i32 @ss7_message(%struct.ss7* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %6)
ret void
}