#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 */

/* Variables and functions */
unsigned int htonl(unsigned int);
void i2c_iaddr_convert(unsigned int iaddr, unsigned int len,
                       unsigned char *addr) {
  union {
    unsigned int iaddr;
    unsigned char caddr[4];
  } convert;
  convert.iaddr = htonl(iaddr);
  int i = len - 1;
  int j = 4 - 1;
  while (i >= 0 && j >= 0) {
    addr[i--] = convert.caddr[j--];
  }
}


x86 assembly (clang, -O0):
<i2c_iaddr_convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x3,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jl     1156 <i2c_iaddr_convert+0x46>
cmpl   $0x0,-0x20(%rbp)
setge  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1166 <i2c_iaddr_convert+0x56>
jmp    1191 <i2c_iaddr_convert+0x81>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cltq
mov    -0x18(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0xffffffff,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    113d <i2c_iaddr_convert+0x2d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_iaddr_convert>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
call   1030 <htonl@plt>
mov    %eax,(%rsp)
mov    %ebx,%eax
add    $0xffffffff,%eax
js     1162 <i2c_iaddr_convert+0x52>
mov    0x3(%rsp),%cl
mov    %eax,%edx
mov    %cl,(%r14,%rdx,1)
test   %eax,%eax
jle    1162 <i2c_iaddr_convert+0x52>
lea    -0x2(%rbx),%eax
mov    0x2(%rsp),%cl
mov    %eax,%edx
mov    %cl,(%r14,%rdx,1)
test   %eax,%eax
jle    1162 <i2c_iaddr_convert+0x52>
lea    -0x3(%rbx),%eax
mov    0x1(%rsp),%cl
mov    %eax,%edx
mov    %cl,(%r14,%rdx,1)
test   %eax,%eax
jle    1162 <i2c_iaddr_convert+0x52>
add    $0xfffffffc,%ebx
mov    (%rsp),%al
mov    %al,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.anon = type { i32 }
define void @i2c_iaddr_convert(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %union.anon
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %4
%11 = call i32 @htonl(i32 %10)
%12 = bitcast %union.anon* %7 to i32*
store i32 %11, i32* %12
%13 = load i32, i32* %5
%14 = sub i32 %13, 1
store i32 %14, i32* %8
store i32 3, i32* %9
br label %15
15: ; preds = %23, %3
%16 = load i32, i32* %8
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* %9
%20 = icmp sge i32 %19, 0
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ false, %15 ], [ %20, %18 ]
br i1 %22, label %23, label %35
23: ; preds = %21
%24 = bitcast %union.anon* %7 to [4 x i8]*
%25 = load i32, i32* %9
%26 = add nsw i32 %25, -1
store i32 %26, i32* %9
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %24, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %6
%31 = load i32, i32* %8
%32 = add nsw i32 %31, -1
store i32 %32, i32* %8
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
br label %15
35: ; preds = %21
ret void
}

LLVM IR (-O2):
%union.anon = type { i32 }
define void @i2c_iaddr_convert(i32 %0, i32 %1, i8* nocapture writeonly %2) {
%4 = alloca %union.anon
%5 = bitcast %union.anon* %4 to i8*
%6 = tail call i32 @htonl(i32 %0)
%7 = getelementptr inbounds %union.anon, %union.anon* %4, i64 0, i32 0
store i32 %6, i32* %7
%8 = add i32 %1, -1
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %37
10: ; preds = %3
%11 = bitcast %union.anon* %4 to [4 x i8]*
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 3
%13 = load i8, i8* %12
%14 = zext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 %13, i8* %15
%16 = add i32 %1, -2
%17 = icmp sgt i32 %8, 0
br i1 %17, label %18, label %37
18: ; preds = %10
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 2
%20 = load i8, i8* %19
%21 = zext i32 %16 to i64
%22 = getelementptr inbounds i8, i8* %2, i64 %21
store i8 %20, i8* %22
%23 = add i32 %1, -3
%24 = icmp sgt i32 %16, 0
br i1 %24, label %25, label %37
25: ; preds = %18
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 1
%27 = load i8, i8* %26
%28 = zext i32 %23 to i64
%29 = getelementptr inbounds i8, i8* %2, i64 %28
store i8 %27, i8* %29
%30 = icmp sgt i32 %23, 0
br i1 %30, label %31, label %37
31: ; preds = %25
%32 = add i32 %1, -4
%33 = bitcast %union.anon* %4 to i8*
%34 = load i8, i8* %33
%35 = zext i32 %32 to i64
%36 = getelementptr inbounds i8, i8* %2, i64 %35
store i8 %34, i8* %36
br label %37
37: ; preds = %10, %18, %25, %31, %3
ret void
}