#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(char const);
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(*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 = %42, %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 %52
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 = %36, %12
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = call i64 @isalnum(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 95
br label %34
34: ; preds = %29, %24
%35 = phi i1 [ true, %24 ], [ %33, %29 ]
br i1 %35, label %36, label %42
36: ; preds = %34
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
%39 = load i8, i8* %37
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %5
store i8 %39, i8* %40
br label %24
42: ; preds = %34
%43 = load i8*, i8** %5
store i8 0, i8* %43
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%45 = call %struct.symbol* @sym_lookup(i8* %44, i32 0)
store %struct.symbol* %45, %struct.symbol** %3
%46 = load %struct.symbol*, %struct.symbol** %3
%47 = call i32 @sym_calc_value(%struct.symbol* %46)
%48 = load %struct.symbol*, %struct.symbol** %3
%49 = call i8* @sym_get_string_value(%struct.symbol* %48)
%50 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %4
store i8* %51, i8** %2
br label %8
52: ; preds = %8
%53 = load i8*, i8** %2
%54 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %53)
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 %34, label %6
6: ; preds = %1, %27
%7 = phi i8* [ %32, %27 ], [ %4, %1 ]
%8 = phi i8* [ %17, %27 ], [ %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 = %24, %6
%15 = phi i8* [ %7, %6 ], [ %17, %24 ]
%16 = phi i8* [ %3, %6 ], [ %26, %24 ]
%17 = getelementptr inbounds i8, i8* %15, i64 1
%18 = load i8, i8* %17
%19 = call i64 @isalnum(i8 signext %18)
%20 = icmp eq i64 %19, 0
%21 = load i8, i8* %17
br i1 %20, label %22, label %24
22: ; preds = %14
%23 = icmp eq i8 %21, 95
br i1 %23, label %24, label %27
24: ; preds = %14, %22
%25 = phi i8 [ 95, %22 ], [ %21, %14 ]
%26 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %25, i8* %16
br label %14
27: ; preds = %22
store i8 0, i8* %16
%28 = call %struct.symbol* @sym_lookup(i8* %3, i32 0)
%29 = call i32 @sym_calc_value(%struct.symbol* %28)
%30 = call i8* @sym_get_string_value(%struct.symbol* %28)
%31 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %30)
%32 = call i8* @strchr(i8* dereferenceable(1) %17, i8 signext 36)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %6
34: ; preds = %27, %1
%35 = phi i8* [ %0, %1 ], [ %17, %27 ]
%36 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0), i8* %35)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @conf_expand_value.res_value, i64 0, i64 0)
}