#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 i2c_msg {
  int len;
  scalar_t__ *buf;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void print_received_data(int i2c_address, const struct i2c_msg *rd_msg) {
  printf("Received data from slave 0x%X:\n", i2c_address);
  int i = 0;
  while (1) {
    printf("0x%X", (unsigned int)rd_msg->buf[i]);
    i++;
    if (i < rd_msg->len) {
      printf(",");
    } else {
      break;
    }
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<print_received_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %eax,%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1192 <print_received_data+0x72>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1197 <print_received_data+0x77>
jmp    119c <print_received_data+0x7c>
jmp    1147 <print_received_data+0x27>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_received_data>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %edi,%esi
lea    0xecf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%rax
mov    (%rax),%esi
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x2,(%r15)
jl     1187 <print_received_data+0x67>
mov    $0x1,%ebx
lea    0xec2(%rip),%r14
xchg   %ax,%ax
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    0x8(%r15),%rax
mov    (%rax,%rbx,8),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq (%r15),%rax
cmp    %rax,%rbx
jl     1160 <print_received_data+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.i2c_msg = type { i32, i64* }
@.str = [32 x i8] c"Received data from slave 0x%X:\0A\00"
@.str.1 = [5 x i8] c"0x%X\00"
@.str.2 = [2 x i8] c",\00"
define void @print_received_data(i32 %0, %struct.i2c_msg* %1) {
%3 = alloca i32
%4 = alloca %struct.i2c_msg*
%5 = alloca i32
store i32 %0, i32* %3
store %struct.i2c_msg* %1, %struct.i2c_msg** %4
%6 = load i32, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 0, i32* %5
br label %8
8: ; preds = %2, %28
%9 = load %struct.i2c_msg*, %struct.i2c_msg** %4
%10 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %9, i32 0, i32 1
%11 = load i64*, i64** %10
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i64, i64* %11, i64 %13
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load %struct.i2c_msg*, %struct.i2c_msg** %4
%22 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %27
25: ; preds = %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
27: ; preds = %8
br label %29
28: ; preds = %25
br label %8
29: ; preds = %27
%30 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
%struct.i2c_msg = type { i32, i64* }
@.str = [32 x i8] c"Received data from slave 0x%X:\0A\00"
@.str.1 = [5 x i8] c"0x%X\00"
define void @print_received_data(i32 %0, %struct.i2c_msg* nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %1, i64 0, i32 1
%5 = load i64*, i64** %4
%6 = load i64, i64* %5
%7 = trunc i64 %6 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %24
12: ; preds = %2, %12
%13 = phi i64 [ %20, %12 ], [ 1, %2 ]
%14 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 44)
%15 = load i64*, i64** %4
%16 = getelementptr inbounds i64, i64* %15, i64 %13
%17 = load i64, i64* %16
%18 = trunc i64 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i64 %13, 1
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %12, label %24
24: ; preds = %12, %2
%25 = tail call i32 @putchar(i8 signext 10)
ret void
}