#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 *state_get_variable(char *);
int strlen(char *);
const char *l_expand_var(const char *var) {
  const char *val;
  char *key;
  key = (char *)(var + 1);
  if (key[0] == '{') {
    key[strlen(key) - 1] = '\0';
    key++;
  }
  val = state_get_variable(key);
  if (!val)
    return "";
  return val;
}


x86 assembly (clang, -O0):
<l_expand_var>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7b,%eax
jne    1175 <l_expand_var+0x55>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <state_get_variable@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119d <l_expand_var+0x7d>
lea    0xe6c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <l_expand_var+0x85>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_expand_var>:
push   %rbx
mov    %rdi,%rbx
add    $0x1,%rdi
cmpb   $0x7b,0x1(%rbx)
jne    1140 <l_expand_var+0x20>
call   1030 <strlen@plt>
cltq
movb   $0x0,(%rbx,%rax,1)
add    $0x2,%rbx
mov    %rbx,%rdi
call   1040 <state_get_variable@plt>
test   %rax,%rax
lea    0xeb1(%rip),%rcx
cmove  %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @l_expand_var(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 123
br i1 %12, label %13, label %22
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
br label %22
22: ; preds = %13, %1
%23 = load i8*, i8** %5
%24 = call i8* @state_get_variable(i8* %23)
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = icmp ne i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %22
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %30
28: ; preds = %22
%29 = load i8*, i8** %4
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %27
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @l_expand_var(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 123
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 0, i8* %9
%10 = getelementptr inbounds i8, i8* %0, i64 2
br label %11
11: ; preds = %5, %1
%12 = phi i8* [ %10, %5 ], [ %2, %1 ]
%13 = tail call i8* @state_get_variable(i8* %12)
%14 = icmp eq i8* %13, null
%15 = select i1 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %13
ret i8* %15
}