#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 /*<<< orphan*/ FILE;

/* Variables and functions */
char *closureContent(char *, char, char);
char *contentToOperator(char *, char, char, char);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ pemdas(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int stackAddressOfVar(char *);
int /*<<< orphan*/ stackPop(int /*<<< orphan*/ *, int);
size_t strlen(char *);
int /*<<< orphan*/ writeAsmBlock(int /*<<< orphan*/ *, char *);
void loadStackAddressOf(FILE *execfile, char *var) {
  char *name = contentToOperator(var, '[', '\0', '\0');
  char *tmp = &var[strlen(name)];
  while (*tmp == ' ')
    tmp = &tmp[1];
  char *arrIndex = NULL;
  if (*tmp == '[')
    arrIndex = closureContent(&tmp[1], '[', ']');
  int stkptr = stackAddressOfVar(name);
  writeAsmBlock(execfile, "mov yh, xh\nmov yl, xl\n");
  char buffer[64];
  sprintf(buffer, "ldi r16, %i\nsub yl, r16", stkptr % 256);
  writeAsmBlock(execfile, buffer);
  sprintf(buffer, "ldi r16, %i\nsbc yl, r16", stkptr / 256);
  writeAsmBlock(execfile, buffer);
  if (arrIndex) {
    pemdas(execfile, arrIndex, 1);
    stackPop(execfile, 16);
    writeAsmBlock(execfile, "add yl, r16\nldi r16, 0\nadc yh, r16\n");
    free(arrIndex);
  }
  free(name);
}


x86 assembly (clang, -O0):
<loadStackAddressOf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5b,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1080 <contentToOperator@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11f9 <loadStackAddressOf+0x69>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d8 <loadStackAddressOf+0x48>
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
jne    122c <loadStackAddressOf+0x9c>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x5b,%esi
mov    $0x5d,%edx
call   1060 <closureContent@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <stackAddressOfVar@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdbd(%rip),%rsi
call   1050 <writeAsmBlock@plt>
lea    -0x70(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
lea    0xdb9(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1050 <writeAsmBlock@plt>
lea    -0x70(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xda7(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1050 <writeAsmBlock@plt>
cmpq   $0x0,-0x28(%rbp)
je     12de <loadStackAddressOf+0x14e>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1070 <pemdas@plt>
mov    -0x8(%rbp),%rdi
mov    $0x10,%esi
call   1090 <stackPop@plt>
mov    -0x8(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1050 <writeAsmBlock@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadStackAddressOf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
mov    $0x5b,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <contentToOperator@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rdi),%eax
cmp    $0x20,%al
jne    11de <loadStackAddressOf+0x4e>
add    $0x1,%rdi
jmp    11d0 <loadStackAddressOf+0x40>
cmp    $0x5b,%al
jne    11f6 <loadStackAddressOf+0x66>
mov    $0x5b,%esi
mov    $0x5d,%edx
call   1060 <closureContent@plt>
mov    %rax,%r15
jmp    11f9 <loadStackAddressOf+0x69>
xor    %r15d,%r15d
mov    %r14,%rdi
call   10b0 <stackAddressOfVar@plt>
mov    %eax,%ebx
lea    0xdf6(%rip),%rsi
mov    %r12,%rdi
call   1050 <writeAsmBlock@plt>
lea    0xff(%rbx),%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
lea    0xdf3(%rip),%rsi
mov    %ebp,%eax
and    $0xffffff00,%eax
sub    %eax,%ebx
mov    %rsp,%r13
mov    %r13,%rdi
mov    %ebx,%edx
call   10a0 <sprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <writeAsmBlock@plt>
sar    $0x8,%ebp
lea    0xde0(%rip),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
call   10a0 <sprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <writeAsmBlock@plt>
test   %r15,%r15
je     129d <loadStackAddressOf+0x10d>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1070 <pemdas@plt>
mov    %r12,%rdi
mov    $0x10,%esi
call   1090 <stackPop@plt>
lea    0xdba(%rip),%rsi
mov    %r12,%rdi
call   1050 <writeAsmBlock@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"mov yh, xh\0Amov yl, xl\0A\00"
@.str.1 = [24 x i8] c"ldi r16, %i\0Asub yl, r16\00"
@.str.2 = [24 x i8] c"ldi r16, %i\0Asbc yl, r16\00"
@.str.3 = [36 x i8] c"add yl, r16\0Aldi r16, 0\0Aadc yh, r16\0A\00"
define void @loadStackAddressOf(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [64 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i8* @contentToOperator(i8* %10, i8 signext 91, i8 signext 0, i8 signext 0)
store i8* %11, i8** %5
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8* %15, i8** %6
br label %16
16: ; preds = %21, %2
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 32
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %6
br label %16
24: ; preds = %16
store i8* null, i8** %7
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 91
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = call i8* @closureContent(i8* %31, i8 signext 91, i8 signext 93)
store i8* %32, i8** %7
br label %33
33: ; preds = %29, %24
%34 = load i8*, i8** %5
%35 = call i32 @stackAddressOfVar(i8* %34)
store i32 %35, i32* %8
%36 = load i32*, i32** %3
%37 = call i32 @writeAsmBlock(i32* %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%39 = load i32, i32* %8
%40 = srem i32 %39, 256
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = load i32*, i32** %3
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%44 = call i32 @writeAsmBlock(i32* %42, i8* %43)
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%46 = load i32, i32* %8
%47 = sdiv i32 %46, 256
%48 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32*, i32** %3
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%51 = call i32 @writeAsmBlock(i32* %49, i8* %50)
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %64
54: ; preds = %33
%55 = load i32*, i32** %3
%56 = load i8*, i8** %7
%57 = call i32 @pemdas(i32* %55, i8* %56, i32 1)
%58 = load i32*, i32** %3
%59 = call i32 @stackPop(i32* %58, i32 16)
%60 = load i32*, i32** %3
%61 = call i32 @writeAsmBlock(i32* %60, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %54, %33
%65 = load i8*, i8** %5
%66 = call i32 @free(i8* %65)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"mov yh, xh\0Amov yl, xl\0A\00"
@.str.1 = [24 x i8] c"ldi r16, %i\0Asub yl, r16\00"
@.str.2 = [24 x i8] c"ldi r16, %i\0Asbc yl, r16\00"
@.str.3 = [36 x i8] c"add yl, r16\0Aldi r16, 0\0Aadc yh, r16\0A\00"
define void @loadStackAddressOf(i32* %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = tail call i8* @contentToOperator(i8* %1, i8 signext 91, i8 signext 0, i8 signext 0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%6 = getelementptr inbounds i8, i8* %1, i64 %5
br label %7
7: ; preds = %10, %2
%8 = phi i8* [ %6, %2 ], [ %11, %10 ]
%9 = load i8, i8* %8
switch i8 %9, label %15 [
i8 32, label %10
i8 91, label %12
]
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %8, i64 1
%14 = tail call i8* @closureContent(i8* %13, i8 signext 91, i8 signext 93)
br label %15
15: ; preds = %7, %12
%16 = phi i8* [ %14, %12 ], [ null, %7 ]
%17 = tail call i32 @stackAddressOfVar(i8* %4)
%18 = tail call i32 @writeAsmBlock(i32* %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%20 = srem i32 %17, 256
%21 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @writeAsmBlock(i32* %0, i8* %19)
%23 = sdiv i32 %17, 256
%24 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = call i32 @writeAsmBlock(i32* %0, i8* %19)
%26 = icmp eq i8* %16, null
br i1 %26, label %32, label %27
27: ; preds = %15
%28 = call i32 @pemdas(i32* %0, i8* %16, i32 1)
%29 = call i32 @stackPop(i32* %0, i32 16)
%30 = call i32 @writeAsmBlock(i32* %0, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @free(i8* %16)
br label %32
32: ; preds = %27, %15
%33 = call i32 @free(i8* %4)
ret void
}