#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 *, unsigned char);
int /*<<< orphan*/ ss7_message(struct ss7 *, char *, int, char *);
void ss7_dump_msg(struct ss7 *ss7, unsigned char *buf, int len) {
  int i;
  char tmp[1024];
  for (i = 0; i < len; i++) {
    snprintf(&tmp[3 * i], sizeof(tmp) - 3 * i, "%02x ", buf[i]);
  }
  ss7_message(ss7, "Len = %d [ %s]\n", len, tmp);
}


x86 assembly (clang, -O0):
<ss7_dump_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1190 <ss7_dump_msg+0x70>
imul   $0x3,-0x18(%rbp),%eax
cltq
lea    -0x420(%rbp),%rdi
add    %rax,%rdi
imul   $0x3,-0x18(%rbp),%eax
movslq %eax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe87(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <ss7_dump_msg+0x1d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x420(%rbp),%rcx
lea    0xe61(%rip),%rsi
call   1040 <ss7_message@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ss7_dump_msg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,0x8(%rsp)
mov    %edx,0x4(%rsp)
test   %edx,%edx
jle    1182 <ss7_dump_msg+0x62>
mov    %rsi,%r12
mov    0x4(%rsp),%r14d
mov    $0x400,%ebp
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
lea    0xea6(%rip),%r13
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%r15,1),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1030 <snprintf@plt>
add    $0x1,%r15
add    $0xfffffffd,%ebp
add    $0x3,%rbx
cmp    %r15,%r14
jne    1160 <ss7_dump_msg+0x40>
lea    0xe7d(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%edx
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 = [6 x i8] c"%02x \00"
@.str.1 = [16 x i8] c"Len = %d [ %s]\0A\00"
define void @ss7_dump_msg(%struct.ss7* %0, i8* %1, i32 %2) {
%4 = alloca %struct.ss7*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store %struct.ss7* %0, %struct.ss7** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %29, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %32
13: ; preds = %9
%14 = load i32, i32* %7
%15 = mul nsw i32 3, %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %16
%18 = load i32, i32* %7
%19 = mul nsw i32 3, %18
%20 = sext i32 %19 to i64
%21 = sub i64 1024, %20
%22 = trunc i64 %21 to i32
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i32 @snprintf(i8* %17, i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %27)
br label %29
29: ; preds = %13
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %9
32: ; preds = %9
%33 = load %struct.ss7*, %struct.ss7** %4
%34 = load i32, i32* %6
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = call i32 @ss7_message(%struct.ss7* %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %34, i8* %35)
ret void
}

LLVM IR (-O2):
%struct.ss7 = type { i32 }
@.str = [6 x i8] c"%02x \00"
@.str.1 = [16 x i8] c"Len = %d [ %s]\0A\00"
define void @ss7_dump_msg(%struct.ss7* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %18, %9 ]
%11 = mul nuw nsw i64 %10, 3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %11
%13 = trunc i64 %11 to i32
%14 = sub nsw i32 1024, %13
%15 = getelementptr inbounds i8, i8* %1, i64 %10
%16 = load i8, i8* %15
%17 = call i32 @snprintf(i8* %12, i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
%18 = add nuw nsw i64 %10, 1
%19 = icmp eq i64 %18, %8
br i1 %19, label %20, label %9
20: ; preds = %9, %3
%21 = call i32 @ss7_message(%struct.ss7* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %5)
ret void
}