#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 */
struct symbol {
  int dummy;
};

/* Variables and functions */
scalar_t__ isalnum(int);
int /*<<< orphan*/ strcat(char *, char const *);
char *strchr(char const *, char);
int /*<<< orphan*/ strncat(char *, char const *, int);
int /*<<< orphan*/ sym_calc_value(struct symbol *);
char const *sym_get_string_value(struct symbol *);
struct symbol *sym_lookup(char *, int /*<<< orphan*/);
char *conf_expand_value(const char *in) {
  struct symbol *sym;
  const char *src;
  static char res_value[256];
  char *dst, name[256];
  res_value[0] = 0;
  dst = name;
  while ((src = strchr(in, '$'))) {
    strncat(res_value, in, src - in);
    src++;
    dst = name;
    while (isalnum((int)*src) || *src == '_')
      *dst++ = *src++;
    *dst = 0;
    sym = sym_lookup(name, 0);
    sym_calc_value(sym);
    strcat(res_value, sym_get_string_value(sym));
    in = src;
  }
  strcat(res_value, in);
  return res_value;
}


x86 assembly (clang, -O0):
<conf_expand_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,0x2eea(%rip)
lea    -0x120(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1296 <conf_expand_value+0x126>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
lea    0x2eab(%rip),%rdi
call   1060 <strncat@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x121(%rbp)
jne    1215 <conf_expand_value+0xa5>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x121(%rbp)
mov    -0x121(%rbp),%al
test   $0x1,%al
jne    1228 <conf_expand_value+0xb8>
jmp    124f <conf_expand_value+0xdf>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11e1 <conf_expand_value+0x71>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
call   1070 <sym_lookup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sym_calc_value@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sym_get_string_value@plt>
mov    %rax,%rsi
lea    0x2dec(%rip),%rdi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <conf_expand_value+0x21>
mov    -0x8(%rbp),%rsi
lea    0x2dcf(%rip),%rdi
call   1090 <strcat@plt>
lea    0x2dc3(%rip),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conf_expand_value>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r13
movb   $0x0,0x2ee6(%rip)
mov    $0x24,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1239 <conf_expand_value+0xc9>
mov    %rax,%r12
mov    %rsp,%r14
lea    0x2ec6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edx
sub    %r13d,%edx
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <strncat@plt>
add    $0x1,%r12
mov    %r12,%r13
mov    %r14,%rbx
jmp    11da <conf_expand_value+0x6a>
nopl   (%rax)
mov    %cl,(%rbx)
add    $0x1,%rbx
add    $0x1,%r13
movsbl 0x0(%r13),%edi
call   1050 <isalnum@plt>
movzbl 0x0(%r13),%ecx
test   %rax,%rax
jne    11d0 <conf_expand_value+0x60>
cmp    $0x5f,%cl
mov    $0x5f,%cl
je     11d0 <conf_expand_value+0x60>
movb   $0x0,(%rbx)
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <sym_lookup@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <sym_calc_value@plt>
mov    %r12,%rdi
call   1080 <sym_get_string_value@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
mov    %r13,%rdi
mov    $0x24,%esi
call   1040 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11b0 <conf_expand_value+0x40>
lea    0x2e30(%rip),%r14
mov    %r14,%rdi
mov    %r13,%rsi
call   1090 <strcat@plt>
mov    %r14,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.symbol = type { i32 }
@conf_expand_value.res_value = internal global [256 x i8] zeroinitializer
define i8* @conf_expand_value(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.symbol*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [256 x i8]
store i8* %0, i8** %2
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8* %7, i8** %5
br label %8
8: ; preds = %43, %1
%9 = load i8*, i8** %2
%10 = call i8* @strchr(i8* %9, i8 signext 36)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %53
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i8*, i8** %4
%15 = load i8*, i8** %2
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %13, i32 %19)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8* %23, i8** %5
br label %24
24: ; preds = %37, %12
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i64 @isalnum(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 95
br label %35
35: ; preds = %30, %24
%36 = phi i1 [ true, %24 ], [ %34, %30 ]
br i1 %36, label %37, label %43
37: ; preds = %35
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %4
%40 = load i8, i8* %38
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
store i8 %40, i8* %41
br label %24
43: ; preds = %35
%44 = load i8*, i8** %5
store i8 0, i8* %44
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%46 = call %struct.symbol* @sym_lookup(i8* %45, i32 0)
store %struct.symbol* %46, %struct.symbol** %3
%47 = load %struct.symbol*, %struct.symbol** %3
%48 = call i32 @sym_calc_value(%struct.symbol* %47)
%49 = load %struct.symbol*, %struct.symbol** %3
%50 = call i8* @sym_get_string_value(%struct.symbol* %49)
%51 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %4
store i8* %52, i8** %2
br label %8
53: ; preds = %8
%54 = load i8*, i8** %2
%55 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %54)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.symbol = type { i32 }
@conf_expand_value.res_value = internal global [256 x i8] zeroinitializer
define i8* @conf_expand_value(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0)
%4 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 36)
%5 = icmp eq i8* %4, null
br i1 %5, label %35, label %6
6: ; preds = %1, %28
%7 = phi i8* [ %33, %28 ], [ %4, %1 ]
%8 = phi i8* [ %17, %28 ], [ %0, %1 ]
%9 = ptrtoint i8* %7 to i64
%10 = ptrtoint i8* %8 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = call i32 @strncat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %8, i32 %12)
br label %14
14: ; preds = %25, %6
%15 = phi i8* [ %7, %6 ], [ %17, %25 ]
%16 = phi i8* [ %3, %6 ], [ %27, %25 ]
%17 = getelementptr inbounds i8, i8* %15, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i64 @isalnum(i32 %19)
%21 = icmp eq i64 %20, 0
%22 = load i8, i8* %17
br i1 %21, label %23, label %25
23: ; preds = %14
%24 = icmp eq i8 %22, 95
br i1 %24, label %25, label %28
25: ; preds = %14, %23
%26 = phi i8 [ 95, %23 ], [ %22, %14 ]
%27 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %26, i8* %16
br label %14
28: ; preds = %23
store i8 0, i8* %16
%29 = call %struct.symbol* @sym_lookup(i8* %3, i32 0)
%30 = call i32 @sym_calc_value(%struct.symbol* %29)
%31 = call i8* @sym_get_string_value(%struct.symbol* %29)
%32 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %31)
%33 = call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 36)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %6
35: ; preds = %28, %1
%36 = phi i8* [ %0, %1 ], [ %17, %28 ]
%37 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %36)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0)
}