#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*/ snprintf(char *, size_t, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void mk_operand(char *operand, size_t operand_sz, const char *stack, int i) {
  switch (stack[i]) {
  case 'D':
    strcpy(operand, "*D");
    break;
  case 'S':
  case 'T':
    operand[0] = stack[i];
    operand[1] = '\0';
    break;
  default:
    snprintf(operand, operand_sz, "stk%d", i + 1);
  }
}


x86 assembly (clang, -O0):
<mk_operand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
sub    $0x44,%eax
je     1168 <mk_operand+0x48>
jmp    1154 <mk_operand+0x34>
mov    -0x20(%rbp),%eax
add    $0xffffffad,%eax
sub    $0x2,%eax
jb     117d <mk_operand+0x5d>
jmp    119b <mk_operand+0x7b>
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11b5 <mk_operand+0x95>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11b5 <mk_operand+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
lea    0xe53(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_operand>:
movslq %ecx,%rax
mov    (%rdx,%rax,1),%r8b
movsbl %r8b,%edx
lea    -0x53(%rdx),%eax
cmp    $0x2,%eax
jae    113b <mk_operand+0x1b>
mov    %r8b,(%rdi)
movb   $0x0,0x1(%rdi)
ret
cmp    $0x44,%edx
jne    114c <mk_operand+0x2c>
lea    0xeb9(%rip),%rsi
jmp    1030 <strcpy@plt>
add    $0x1,%ecx
lea    0xead(%rip),%rdx
jmp    1040 <snprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"*D\00"
@.str.1 = [6 x i8] c"stk%d\00"
define void @mk_operand(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i8*, i8** %7
%10 = load i32, i32* %8
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
switch i32 %14, label %28 [
i32 68, label %15
i32 83, label %18
i32 84, label %18
]
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %34
18: ; preds = %4, %4
%19 = load i8*, i8** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 %23, i8* %25
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8 0, i8* %27
br label %34
28: ; preds = %4
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
%33 = call i32 @snprintf(i8* %29, i64 %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %28, %18, %15
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"*D\00"
@.str.1 = [6 x i8] c"stk%d\00"
define void @mk_operand(i8* %0, i64 %1, i8* nocapture %2, i32 %3) {
%5 = sext i32 %3 to i64
%6 = getelementptr inbounds i8, i8* %2, i64 %5
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %13 [
i32 68, label %9
i32 83, label %11
i32 84, label %11
]
9: ; preds = %4
%10 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %4, %4
store i8 %7, i8* %0
%12 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %12
br label %16
13: ; preds = %4
%14 = add nsw i32 %3, 1
%15 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %11, %9
ret void
}