#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 */
int /*<<< orphan*/ delay_ms(int);
int /*<<< orphan*/ eeprom_write(short, unsigned short);
void write_code(unsigned long code) {
  short idx;
  unsigned short *_code = (unsigned short *)(&code);
  for (idx = 0; idx < 4; idx++) {
    delay_ms(20);
    eeprom_write(idx, _code[idx]);
  }
}


x86 assembly (clang, -O0):
<write_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movw   $0x0,-0xa(%rbp)
movswl -0xa(%rbp),%eax
cmp    $0x4,%eax
jge    117b <write_code+0x5b>
mov    $0x14,%edi
call   1030 <delay_ms@plt>
mov    -0xa(%rbp),%dx
mov    -0x18(%rbp),%rax
movswq -0xa(%rbp),%rcx
movswl %dx,%edi
movzwl (%rax,%rcx,2),%esi
call   1040 <eeprom_write@plt>
mov    -0xa(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xa(%rbp)
jmp    113a <write_code+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_code>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    %rdi,%r15
shr    $0x20,%r15
mov    %rdi,%r14
shr    $0x30,%r14
mov    $0x14,%edi
call   1030 <delay_ms@plt>
movzwl %bx,%esi
xor    %edi,%edi
call   1040 <eeprom_write@plt>
mov    $0x14,%edi
call   1030 <delay_ms@plt>
shr    $0x10,%ebx
mov    $0x1,%edi
mov    %ebx,%esi
call   1040 <eeprom_write@plt>
mov    $0x14,%edi
call   1030 <delay_ms@plt>
movzwl %r15w,%esi
mov    $0x2,%edi
call   1040 <eeprom_write@plt>
mov    $0x14,%edi
call   1030 <delay_ms@plt>
mov    $0x3,%edi
mov    %r14d,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <eeprom_write@plt>

LLVM IR (-O0):
define void @write_code(i64 %0) {
%2 = alloca i64
%3 = alloca i16
%4 = alloca i16*
store i64 %0, i64* %2
%5 = bitcast i64* %2 to i16*
store i16* %5, i16** %4
store i16 0, i16* %3
br label %6
6: ; preds = %19, %1
%7 = load i16, i16* %3
%8 = sext i16 %7 to i32
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = call i32 @delay_ms(i32 20)
%12 = load i16, i16* %3
%13 = load i16*, i16** %4
%14 = load i16, i16* %3
%15 = sext i16 %14 to i64
%16 = getelementptr inbounds i16, i16* %13, i64 %15
%17 = load i16, i16* %16
%18 = call i32 @eeprom_write(i16 signext %12, i16 zeroext %17)
br label %19
19: ; preds = %10
%20 = load i16, i16* %3
%21 = add i16 %20, 1
store i16 %21, i16* %3
br label %6
22: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @write_code(i64 %0) {
%2 = trunc i64 %0 to i16
%3 = lshr i64 %0, 16
%4 = trunc i64 %3 to i16
%5 = lshr i64 %0, 32
%6 = trunc i64 %5 to i16
%7 = lshr i64 %0, 48
%8 = trunc i64 %7 to i16
%9 = tail call i32 @delay_ms(i32 20)
%10 = tail call i32 @eeprom_write(i16 signext 0, i16 zeroext %2)
%11 = tail call i32 @delay_ms(i32 20)
%12 = tail call i32 @eeprom_write(i16 signext 1, i16 zeroext %4)
%13 = tail call i32 @delay_ms(i32 20)
%14 = tail call i32 @eeprom_write(i16 signext 2, i16 zeroext %6)
%15 = tail call i32 @delay_ms(i32 20)
%16 = tail call i32 @eeprom_write(i16 signext 3, i16 zeroext %8)
ret void
}