#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*/ checksum(char *, int, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void memIndexToAddr(int idx, char *cmd) {
  char cs[3];
  int addr = 0x0C00 + (idx * 0x40);
  sprintf(cmd, "ER%04X%02X__;", addr, 0x40);
  checksum(cmd, 2, 2 + 6, cs);
  strncpy(cmd + 2 + 6, cs, 2);
}


x86 assembly (clang, -O0):
<memIndexToAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x6,%eax
add    $0xc00,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xea5(%rip),%rsi
mov    $0x40,%ecx
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x13(%rbp),%rcx
mov    $0x2,%esi
mov    $0x8,%edx
call   1040 <checksum@plt>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
add    $0x6,%rdi
lea    -0x13(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memIndexToAddr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
shl    $0x6,%edi
lea    0xc00(%rdi),%edx
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
mov    $0x40,%ecx
call   1050 <sprintf@plt>
lea    0x5(%rsp),%r14
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1040 <checksum@plt>
add    $0x8,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"ER%04X%02X__;\00"
define void @memIndexToAddr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = mul nsw i32 %7, 64
%9 = add nsw i32 3072, %8
store i32 %9, i32* %6
%10 = load i8*, i8** %4
%11 = load i32, i32* %6
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11, i32 64)
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%15 = call i32 @checksum(i8* %13, i32 2, i32 8, i8* %14)
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 2
%18 = getelementptr inbounds i8, i8* %17, i64 6
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%20 = call i32 @strncpy(i8* %18, i8* %19, i32 2)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"ER%04X%02X__;\00"
define void @memIndexToAddr(i32 %0, i8* %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = shl nsw i32 %0, 6
%6 = add nsw i32 %5, 3072
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6, i32 64)
%8 = call i32 @checksum(i8* %1, i32 2, i32 8, i8* %4)
%9 = getelementptr inbounds i8, i8* %1, i64 8
%10 = call i32 @strncpy(i8* %9, i8* %4, i32 2)
ret void
}