#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 uint16_t;
typedef scalar_t__ curr_value;

/* Variables and functions */
int htons(int const);
void _icon_tbetb(const uint16_t icon[], char *buffer, int offset) {
  uint16_t curr_value;
  for (int i = 0; i < 256; i++) {
    curr_value = htons(icon[i]);
    buffer[offset + i * 2 + 1] = (char)((curr_value)&0xFF);
    buffer[offset + i * 2] = (char)((curr_value >> 8) & 0xFF);
  }
}


x86 assembly (clang, -O0):
<_icon_tbetb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    119c <_icon_tbetb+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%esi
shl    $0x1,%esi
add    %esi,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%esi
shl    $0x1,%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <_icon_tbetb+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_icon_tbetb>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
movslq %edx,%rax
lea    (%rax,%rsi,1),%r15
add    $0x1,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,4),%edi
call   1030 <htons@plt>
rol    $0x8,%ax
mov    %ax,-0x1(%r15,%rbx,2)
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    1130 <_icon_tbetb+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @_icon_tbetb(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
br label %9
9: ; preds = %41, %3
%10 = load i32, i32* %8
%11 = icmp slt i32 %10, 256
br i1 %11, label %12, label %44
12: ; preds = %9
%13 = load i32*, i32** %4
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @htons(i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = load i32, i32* %8
%25 = mul nsw i32 %24, 2
%26 = add nsw i32 %23, %25
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %22, i64 %28
store i8 %21, i8* %29
%30 = load i32, i32* %7
%31 = ashr i32 %30, 8
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %5
%35 = load i32, i32* %6
%36 = load i32, i32* %8
%37 = mul nsw i32 %36, 2
%38 = add nsw i32 %35, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %34, i64 %39
store i8 %33, i8* %40
br label %41
41: ; preds = %12
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %9
44: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @_icon_tbetb(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = sext i32 %2 to i64
br label %6
5: ; preds = %6
ret void
6: ; preds = %3, %6
%7 = phi i64 [ 0, %3 ], [ %19, %6 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = tail call i32 @htons(i32 %9)
%11 = trunc i32 %10 to i8
%12 = shl nuw nsw i64 %7, 1
%13 = add nsw i64 %12, %4
%14 = add nsw i64 %13, 1
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %11, i8* %15
%16 = lshr i32 %10, 8
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %17, i8* %18
%19 = add nuw nsw i64 %7, 1
%20 = icmp eq i64 %19, 256
br i1 %20, label %5, label %6
}