#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 addr;
  int flags;
  int len;
  int *buf;
};

/* Variables and functions */
int I2C_M_RD;
int /*<<< orphan*/ printf(char *, ...);
void dump_i2c_msg(struct i2c_msg *msg) {
  int i;
  printf("Addr:\t0x%02x [%c]\n", msg->addr, msg->flags & I2C_M_RD ? 'R' : 'W');
  printf("Flags:\t0x%02x\n", msg->flags);
  printf(" len:\t%d\n", msg->len);
  printf("data:\t");
  for (i = 0; i < msg->len; i++) {
    printf("0x%02x ", msg->buf[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_i2c_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    0x2eb0(%rip),%rax
and    (%rax),%ecx
mov    $0x57,%edx
mov    $0x52,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    0x8(%rcx),%eax
jge    11ca <dump_i2c_msg+0xba>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118f <dump_i2c_msg+0x7f>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_i2c_msg>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    (%rdi),%esi
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
and    0x4(%rdi),%eax
sete   %cl
lea    (%rcx,%rcx,4),%edx
add    $0x52,%edx
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%r15),%esi
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%esi
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x8(%r15)
jle    11be <dump_i2c_msg+0x9e>
lea    0xea4(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%r15),%rax
mov    (%rax,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%r15),%rax
cmp    %rax,%rbx
jl     11a0 <dump_i2c_msg+0x80>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.i2c_msg = type { i32, i32, i32, i32* }
@.str = [19 x i8] c"Addr:\090x%02x [%c]\0A\00"
@I2C_M_RD = global i32 0
@.str.1 = [15 x i8] c"Flags:\090x%02x\0A\00"
@.str.2 = [10 x i8] c" len:\09%d\0A\00"
@.str.3 = [7 x i8] c"data:\09\00"
@.str.4 = [8 x i8] c"0x%02x \00"
@.str.5 = [2 x i8] c"\0A\00"
define void @dump_i2c_msg(%struct.i2c_msg* %0) {
%2 = alloca %struct.i2c_msg*
%3 = alloca i32
store %struct.i2c_msg* %0, %struct.i2c_msg** %2
%4 = load %struct.i2c_msg*, %struct.i2c_msg** %2
%5 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = load %struct.i2c_msg*, %struct.i2c_msg** %2
%8 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %7, i32 0, i32 1
%9 = load i32, i32* %8
%10 = load i32, i32* @I2C_M_RD
%11 = and i32 %9, %10
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 82, i32 87
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %14)
%16 = load %struct.i2c_msg*, %struct.i2c_msg** %2
%17 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load %struct.i2c_msg*, %struct.i2c_msg** %2
%21 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %25
25: ; preds = %40, %1
%26 = load i32, i32* %3
%27 = load %struct.i2c_msg*, %struct.i2c_msg** %2
%28 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %27, i32 0, i32 2
%29 = load i32, i32* %28
%30 = icmp slt i32 %26, %29
br i1 %30, label %31, label %43
31: ; preds = %25
%32 = load %struct.i2c_msg*, %struct.i2c_msg** %2
%33 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %32, i32 0, i32 3
%34 = load i32*, i32** %33
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %31
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %25
43: ; preds = %25
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.i2c_msg = type { i32, i32, i32, i32* }
@.str = [19 x i8] c"Addr:\090x%02x [%c]\0A\00"
@I2C_M_RD = global i32 0
@.str.1 = [15 x i8] c"Flags:\090x%02x\0A\00"
@.str.2 = [10 x i8] c" len:\09%d\0A\00"
@.str.3 = [7 x i8] c"data:\09\00"
@.str.4 = [8 x i8] c"0x%02x \00"
define void @dump_i2c_msg(%struct.i2c_msg* nocapture %0) {
%2 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = load i32, i32* @I2C_M_RD
%7 = and i32 %6, %5
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 87, i32 82
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %9)
%11 = load i32, i32* %4
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 2
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %13
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %1
%20 = getelementptr inbounds %struct.i2c_msg, %struct.i2c_msg* %0, i64 0, i32 3
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %27, %21 ]
%23 = load i32*, i32** %20
%24 = getelementptr inbounds i32, i32* %23, i64 %22
%25 = load i32, i32* %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %22, 1
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %21, label %31
31: ; preds = %21, %1
%32 = tail call i32 @putchar(i32 10)
ret void
}