#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*/ BlockMove(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ GetIndString(unsigned char *, int, int);
void set_key_note_txt(unsigned char g, unsigned char *txt) {
  static unsigned char note_str[20] = {0};
  short idx = (g & 0x07) + 1;
  if (note_str[0] == 0)
    GetIndString(note_str, 128, 6);
  if (note_str[0] < 9) {
    txt[0] = 1;
    txt[1] = note_str[idx];
  } else {
    txt[0] = 2;
    BlockMove(&note_str[idx * 2 - 1], &txt[1], 2);
  }
}


x86 assembly (clang, -O0):
<set_key_note_txt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x7,%eax
add    $0x1,%eax
mov    %ax,-0x12(%rbp)
movzbl 0x2ef9(%rip),%eax
cmp    $0x0,%eax
jne    1166 <set_key_note_txt+0x46>
lea    0x2ee9(%rip),%rdi
mov    $0x80,%esi
mov    $0x6,%edx
call   1040 <GetIndString@plt>
movzbl 0x2ed3(%rip),%eax
cmp    $0x9,%eax
jge    1198 <set_key_note_txt+0x78>
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
movswq -0x12(%rbp),%rcx
lea    0x2eb7(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    11c7 <set_key_note_txt+0xa7>
mov    -0x10(%rbp),%rax
movb   $0x2,(%rax)
movswl -0x12(%rbp),%eax
shl    $0x1,%eax
sub    $0x1,%eax
cltq
lea    0x2e8e(%rip),%rdi
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0x2,%edx
call   1030 <BlockMove@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_key_note_txt>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
and    $0x7,%ebx
mov    0x2f0e(%rip),%al
test   %al,%al
jne    1152 <set_key_note_txt+0x32>
lea    0x2f03(%rip),%rdi
mov    $0x80,%esi
mov    $0x6,%edx
call   1040 <GetIndString@plt>
mov    0x2eee(%rip),%al
add    $0x1,%rbx
cmp    $0x8,%al
ja     1174 <set_key_note_txt+0x54>
movb   $0x1,(%r14)
lea    0x2edb(%rip),%rax
mov    (%rbx,%rax,1),%al
mov    %al,0x1(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movb   $0x2,(%r14)
movzbl %bl,%eax
add    %eax,%eax
add    $0xffffffff,%eax
lea    0x2eb9(%rip),%rdi
add    %rax,%rdi
add    $0x1,%r14
mov    %r14,%rsi
mov    $0x2,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <BlockMove@plt>

LLVM IR (-O0):
@set_key_note_txt.note_str = internal global [20 x i8] zeroinitializer
define void @set_key_note_txt(i8 zeroext %0, i8* %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i16
store i8 %0, i8* %3
store i8* %1, i8** %4
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = and i32 %7, 7
%9 = add nsw i32 %8, 1
%10 = trunc i32 %9 to i16
store i16 %10, i16* %5
%11 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 0)
%12 = zext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @GetIndString(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 0), i32 128, i32 6)
br label %16
16: ; preds = %14, %2
%17 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 0)
%18 = zext i8 %17 to i32
%19 = icmp slt i32 %18, 9
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 1, i8* %22
%23 = load i16, i16* %5
%24 = sext i16 %23 to i64
%25 = getelementptr inbounds [20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 %26, i8* %28
br label %41
29: ; preds = %16
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
store i8 2, i8* %31
%32 = load i16, i16* %5
%33 = sext i16 %32 to i32
%34 = mul nsw i32 %33, 2
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 %36
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = call i32 @BlockMove(i8* %37, i8* %39, i32 2)
br label %41
41: ; preds = %29, %20
ret void
}

LLVM IR (-O2):
@set_key_note_txt.note_str = internal global [20 x i8] zeroinitializer
define void @set_key_note_txt(i8 zeroext %0, i8* %1) {
%3 = and i8 %0, 7
%4 = add nuw nsw i8 %3, 1
%5 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 0)
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @GetIndString(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 0), i32 128, i32 6)
%9 = load i8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 0)
br label %10
10: ; preds = %7, %2
%11 = phi i8 [ %9, %7 ], [ %5, %2 ]
%12 = icmp ult i8 %11, 9
br i1 %12, label %13, label %18
13: ; preds = %10
store i8 1, i8* %1
%14 = zext i8 %4 to i64
%15 = getelementptr inbounds [20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %16, i8* %17
br label %26
18: ; preds = %10
store i8 2, i8* %1
%19 = shl nuw nsw i8 %4, 1
%20 = zext i8 %19 to i64
%21 = add nuw nsw i64 %20, 4294967295
%22 = and i64 %21, 4294967295
%23 = getelementptr inbounds [20 x i8], [20 x i8]* @set_key_note_txt.note_str, i64 0, i64 %22
%24 = getelementptr inbounds i8, i8* %1, i64 1
%25 = tail call i32 @BlockMove(i8* %23, i8* %24, i32 2)
br label %26
26: ; preds = %18, %13
ret void
}