#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*/ uint8_t;
typedef scalar_t__ uint64_t;
struct message {
  int dummy;
};

/* Variables and functions */
scalar_t__ msg_get_count(struct message *);
int /*<<< orphan*/ msg_get_elem(struct message *, scalar_t__,
                                int /*<<< orphan*/ **, scalar_t__ *);
int /*<<< orphan*/ print_buf(int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ printf(char *, scalar_t__);
void print_message(struct message *msg) {
  uint64_t count = msg_get_count(msg);
  printf("count = %llu\n", count);
  for (uint64_t i = 0; i < count; i++) {
    uint8_t *data;
    uint64_t size;
    msg_get_elem(msg, i, &data, &size);
    printf("index = %llu\n", i);
    print_buf(data, size);
  }
}


x86 assembly (clang, -O0):
<print_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <msg_get_count@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe9c(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11c2 <print_message+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <msg_get_elem@plt>
mov    -0x18(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <print_buf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <print_message+0x31>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1060 <msg_get_count@plt>
mov    %rax,%r15
lea    0xea0(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
test   %r15,%r15
jle    11b4 <print_message+0x74>
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0xe8e(%rip),%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <msg_get_elem@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1030 <print_buf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <print_message+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.message = type { i32 }
@.str = [14 x i8] c"count = %llu\0A\00"
@.str.1 = [14 x i8] c"index = %llu\0A\00"
define void @print_message(%struct.message* %0) {
%2 = alloca %struct.message*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
store %struct.message* %0, %struct.message** %2
%7 = load %struct.message*, %struct.message** %2
%8 = call i64 @msg_get_count(%struct.message* %7)
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %9)
store i64 0, i64* %4
br label %11
11: ; preds = %24, %1
%12 = load i64, i64* %4
%13 = load i64, i64* %3
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load %struct.message*, %struct.message** %2
%17 = load i64, i64* %4
%18 = call i32 @msg_get_elem(%struct.message* %16, i64 %17, i32** %5, i64* %6)
%19 = load i64, i64* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = load i32*, i32** %5
%22 = load i64, i64* %6
%23 = call i32 @print_buf(i32* %21, i64 %22)
br label %24
24: ; preds = %15
%25 = load i64, i64* %4
%26 = add nsw i64 %25, 1
store i64 %26, i64* %4
br label %11
27: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.message = type { i32 }
@.str = [14 x i8] c"count = %llu\0A\00"
@.str.1 = [14 x i8] c"index = %llu\0A\00"
define void @print_message(%struct.message* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = tail call i64 @msg_get_count(%struct.message* %0)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = icmp sgt i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = bitcast i32** %2 to i8*
%9 = bitcast i64* %3 to i8*
br label %11
10: ; preds = %11, %1
ret void
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %18, %11 ]
%13 = call i32 @msg_get_elem(%struct.message* %0, i64 %12, i32** %2, i64* %3)
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %12)
%15 = load i32*, i32** %2
%16 = load i64, i64* %3
%17 = call i32 @print_buf(i32* %15, i64 %16)
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %4
br i1 %19, label %10, label %11
}