#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 */
char *consume_token(char *, unsigned char);
int /*<<< orphan*/ create_variable(unsigned int, unsigned char, ...);
int /*<<< orphan*/ delete_variable(unsigned int, unsigned char);
int next_token(char *);
int /*<<< orphan*/ parse_number_expression(char *, int *);
int /*<<< orphan*/ parse_string_expression(char *, char **);
char *parse_variable(char *, unsigned int *, unsigned char *);
int /*<<< orphan*/ print_all_variables();
int /*<<< orphan*/ print_ready();
int /*<<< orphan*/ skip_whitespace(char *);
int /*<<< orphan*/ syntax_error();
void cmd_let(char *args) {
  unsigned char token;
  unsigned int var_name;
  unsigned char var_type;
  skip_whitespace(args);
  if (*args == '\0') {
    print_all_variables();
    print_ready();
    return;
  }
  if (args = parse_variable(args, &var_name, &var_type)) {
    if (next_token(args) == 6) {
      token = next_token(args);
      args = consume_token(args, token);
      switch (var_type) {
      case 0: {
        int value;
        if (parse_number_expression(args, &value)) {
          create_variable(var_name, var_type, &value);
        }
        break;
      }
      case 1: {
        char *value;
        if (parse_string_expression(args, &value)) {
          create_variable(var_name, var_type, value);
        }
        break;
      }
      }
    } else {
      if (*args == '\0') {
        delete_variable(var_name, var_type);
      }
    }
  } else {
    syntax_error();
  }
}


x86 assembly (clang, -O0):
<cmd_let>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <skip_whitespace@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e8 <cmd_let+0x38>
mov    $0x0,%al
call   10c0 <print_all_variables@plt>
mov    $0x0,%al
call   1040 <print_ready@plt>
jmp    12e9 <cmd_let+0x139>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x11(%rbp),%rdx
call   10b0 <parse_variable@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     12e2 <cmd_let+0x132>
mov    -0x8(%rbp),%rdi
call   1090 <next_token@plt>
cmp    $0x6,%eax
jne    12bc <cmd_let+0x10c>
mov    -0x8(%rbp),%rdi
call   1090 <next_token@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%esi
call   10d0 <consume_token@plt>
mov    %rax,-0x8(%rbp)
movzbl -0x11(%rbp),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     125b <cmd_let+0xab>
jmp    124a <cmd_let+0x9a>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     1288 <cmd_let+0xd8>
jmp    12b7 <cmd_let+0x107>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <parse_number_expression@plt>
cmp    $0x0,%eax
je     1283 <cmd_let+0xd3>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rdx
movzbl -0x11(%rbp),%esi
mov    $0x0,%al
call   1030 <create_variable@plt>
jmp    12b7 <cmd_let+0x107>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <parse_string_expression@plt>
cmp    $0x0,%eax
je     12b2 <cmd_let+0x102>
mov    -0x10(%rbp),%edi
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rdx
movzbl %al,%esi
mov    $0x0,%al
call   1030 <create_variable@plt>
jmp    12b7 <cmd_let+0x107>
jmp    12dd <cmd_let+0x12d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12d8 <cmd_let+0x128>
mov    -0x10(%rbp),%edi
movzbl -0x11(%rbp),%esi
call   1080 <delete_variable@plt>
jmp    12dd <cmd_let+0x12d>
jmp    12e9 <cmd_let+0x139>
mov    $0x0,%al
call   10a0 <syntax_error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_let>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1060 <skip_whitespace@plt>
cmpb   $0x0,(%rbx)
je     122a <cmd_let+0x7a>
lea    0x4(%rsp),%rsi
lea    0x3(%rsp),%rdx
mov    %rbx,%rdi
call   10b0 <parse_variable@plt>
test   %rax,%rax
je     123d <cmd_let+0x8d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <next_token@plt>
cmp    $0x6,%eax
jne    1246 <cmd_let+0x96>
mov    %rbx,%rdi
call   1090 <next_token@plt>
movzbl %al,%esi
mov    %rbx,%rdi
call   10d0 <consume_token@plt>
mov    0x3(%rsp),%cl
cmp    $0x1,%cl
je     125b <cmd_let+0xab>
test   %cl,%cl
jne    1281 <cmd_let+0xd1>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1070 <parse_number_expression@plt>
test   %eax,%eax
je     1281 <cmd_let+0xd1>
mov    0x4(%rsp),%edi
movzbl 0x3(%rsp),%esi
lea    0x8(%rsp),%rdx
jmp    127a <cmd_let+0xca>
xor    %eax,%eax
call   10c0 <print_all_variables@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
jmp    1040 <print_ready@plt>
xor    %eax,%eax
call   10a0 <syntax_error@plt>
jmp    1281 <cmd_let+0xd1>
cmpb   $0x0,(%rbx)
jne    1281 <cmd_let+0xd1>
mov    0x4(%rsp),%edi
movzbl 0x3(%rsp),%esi
call   1080 <delete_variable@plt>
jmp    1281 <cmd_let+0xd1>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <parse_string_expression@plt>
test   %eax,%eax
je     1281 <cmd_let+0xd1>
mov    0x4(%rsp),%edi
movzbl 0x3(%rsp),%esi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1030 <create_variable@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @cmd_let(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @skip_whitespace(i8* %8)
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 (...) @print_all_variables()
%16 = call i32 (...) @print_ready()
br label %67
17: ; preds = %1
%18 = load i8*, i8** %2
%19 = call i8* @parse_variable(i8* %18, i32* %4, i8* %5)
store i8* %19, i8** %2
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %65
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i32 @next_token(i8* %22)
%24 = icmp eq i32 %23, 6
br i1 %24, label %25, label %54
25: ; preds = %21
%26 = load i8*, i8** %2
%27 = call i32 @next_token(i8* %26)
%28 = trunc i32 %27 to i8
store i8 %28, i8* %3
%29 = load i8*, i8** %2
%30 = load i8, i8* %3
%31 = call i8* @consume_token(i8* %29, i8 zeroext %30)
store i8* %31, i8** %2
%32 = load i8, i8* %5
%33 = zext i8 %32 to i32
switch i32 %33, label %53 [
i32 0, label %34
i32 1, label %43
]
34: ; preds = %25
%35 = load i8*, i8** %2
%36 = call i32 @parse_number_expression(i8* %35, i32* %6)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %4
%40 = load i8, i8* %5
%41 = call i32 (i32, i8, ...) @create_variable(i32 %39, i8 zeroext %40, i32* %6)
br label %42
42: ; preds = %38, %34
br label %53
43: ; preds = %25
%44 = load i8*, i8** %2
%45 = call i32 @parse_string_expression(i8* %44, i8** %7)
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i32, i32* %4
%49 = load i8, i8* %5
%50 = load i8*, i8** %7
%51 = call i32 (i32, i8, ...) @create_variable(i32 %48, i8 zeroext %49, i8* %50)
br label %52
52: ; preds = %47, %43
br label %53
53: ; preds = %25, %52, %42
br label %64
54: ; preds = %21
%55 = load i8*, i8** %2
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %54
%60 = load i32, i32* %4
%61 = load i8, i8* %5
%62 = call i32 @delete_variable(i32 %60, i8 zeroext %61)
br label %63
63: ; preds = %59, %54
br label %64
64: ; preds = %63, %53
br label %67
65: ; preds = %17
%66 = call i32 (...) @syntax_error()
br label %67
67: ; preds = %14, %65, %64
ret void
}

LLVM IR (-O2):
define void @cmd_let(i8* %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %2 to i8*
%7 = tail call i32 @skip_whitespace(i8* %0)
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = tail call i32 (...) @print_all_variables()
%12 = tail call i32 (...) @print_ready()
br label %52
13: ; preds = %1
%14 = call i8* @parse_variable(i8* %0, i32* %2, i8* %3)
%15 = icmp eq i8* %14, null
br i1 %15, label %50, label %16
16: ; preds = %13
%17 = call i32 @next_token(i8* %14)
%18 = icmp eq i32 %17, 6
br i1 %18, label %19, label %43
19: ; preds = %16
%20 = call i32 @next_token(i8* %14)
%21 = trunc i32 %20 to i8
%22 = call i8* @consume_token(i8* %14, i8 zeroext %21)
%23 = load i8, i8* %3
switch i8 %23, label %52 [
i8 0, label %24
i8 1, label %33
]
24: ; preds = %19
%25 = bitcast i32* %4 to i8*
%26 = call i32 @parse_number_expression(i8* %22, i32* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i32, i32* %2
%30 = load i8, i8* %3
%31 = call i32 (i32, i8, ...) @create_variable(i32 %29, i8 zeroext %30, i32* %4)
br label %32
32: ; preds = %28, %24
br label %52
33: ; preds = %19
%34 = bitcast i8** %5 to i8*
%35 = call i32 @parse_string_expression(i8* %22, i8** %5)
%36 = icmp eq i32 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %33
%38 = load i32, i32* %2
%39 = load i8, i8* %3
%40 = load i8*, i8** %5
%41 = call i32 (i32, i8, ...) @create_variable(i32 %38, i8 zeroext %39, i8* %40)
br label %42
42: ; preds = %37, %33
br label %52
43: ; preds = %16
%44 = load i8, i8* %14
%45 = icmp eq i8 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = load i32, i32* %2
%48 = load i8, i8* %3
%49 = call i32 @delete_variable(i32 %47, i8 zeroext %48)
br label %52
50: ; preds = %13
%51 = call i32 (...) @syntax_error()
br label %52
52: ; preds = %50, %43, %46, %32, %42, %19, %10
ret void
}