#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 Node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int MAX_INPUT;
char *calloc(int, int);
int /*<<< orphan*/ delete_node(struct Node *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ find_variables(struct Node *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ has_variables(struct Node *);
struct Node *parse(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ reduce(struct Node *);
int /*<<< orphan*/ replace(char, struct Node **, struct Node *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
void replace_variables(struct Node **root) {
  char *variables, *i;
  char input[MAX_INPUT];
  struct Node *value;
  while (has_variables(*root)) {
    if ((variables = calloc(1, sizeof(char))) == NULL) {
      perror("calloc");
      exit(EXIT_FAILURE);
    }
    find_variables(*root, &variables);
    for (i = variables; *i != '\0'; i++) {
      printf("value of variable %c: ", *i);
      fgets(input, MAX_INPUT - 1, stdin);
      input[strlen(input) - 1] = '\0';
      value = parse(input);
      if (value == NULL) {
        fprintf(stderr, "cannot create parse tree\n");
        i--;
        continue;
      }
      reduce(value);
      replace(*i, root, value);
      delete_node(value);
    }
    free(variables);
  }
}


x86 assembly (clang, -O0):
<replace_variables>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <has_variables@plt>
cmp    $0x0,%rax
je     1352 <replace_variables+0x172>
mov    $0x1,%esi
mov    %esi,%edi
call   1080 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1262 <replace_variables+0x82>
lea    0xdb1(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    -0x10(%rbp),%rsi
call   10c0 <find_variables@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1344 <replace_variables+0x164>
mov    -0x18(%rbp),%rax
lea    0xd72(%rip),%rdi
movsbl (%rax),%esi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
call   1070 <fgets@plt>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
sub    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
call   10f0 <parse@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    130b <replace_variables+0x12b>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd29(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1333 <replace_variables+0x153>
mov    -0x30(%rbp),%rdi
call   1040 <reduce@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
mov    -0x30(%rbp),%rdx
movsbl %al,%edi
call   10d0 <replace@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <delete_node@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    127a <replace_variables+0x9a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1218 <replace_variables+0x38>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_variables>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %rsp,-0x38(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    (%rdi),%rdi
call   10b0 <has_variables@plt>
test   %rax,%rax
je     1322 <replace_variables+0x142>
lea    0xddd(%rip),%r12
jmp    124d <replace_variables+0x6d>
nopl   0x0(%rax)
mov    -0x30(%rbp),%r15
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%r14),%rdi
call   10b0 <has_variables@plt>
test   %rax,%rax
je     1322 <replace_variables+0x142>
mov    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
test   %rax,%rax
je     1335 <replace_variables+0x155>
mov    (%r14),%rdi
lea    -0x30(%rbp),%rsi
call   10c0 <find_variables@plt>
mov    -0x30(%rbp),%r15
mov    (%r15),%al
test   %al,%al
jne    12c3 <replace_variables+0xe3>
jmp    1234 <replace_variables+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <reduce@plt>
movsbl (%r15),%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   10d0 <replace@plt>
mov    %r13,%rdi
call   10a0 <delete_node@plt>
movzbl 0x1(%r15),%eax
add    $0x1,%r15
test   %al,%al
je     1230 <replace_variables+0x50>
movsbl %al,%esi
mov    %r12,%rdi
call   1060 <printf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
add    $0xffffffff,%esi
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   10f0 <parse@plt>
test   %rax,%rax
jne    1290 <replace_variables+0xb0>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
lea    0xd07(%rip),%rsi
call   1090 <fprintf@plt>
add    $0xffffffffffffffff,%r15
jmp    12b2 <replace_variables+0xd2>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc4(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.Node = type { i32 }
@MAX_INPUT = global i32 0
@.str = [7 x i8] c"calloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"value of variable %c: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"cannot create parse tree\0A\00"
define void @replace_variables(%struct.Node** %0) {
%2 = alloca %struct.Node**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.Node*
store %struct.Node** %0, %struct.Node*** %2
%8 = load i32, i32* @MAX_INPUT
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
br label %12
12: ; preds = %67, %1
%13 = load %struct.Node**, %struct.Node*** %2
%14 = load %struct.Node*, %struct.Node** %13
%15 = call i64 @has_variables(%struct.Node* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %70
17: ; preds = %12
%18 = call i8* @calloc(i32 1, i32 1)
store i8* %18, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %17
%25 = load %struct.Node**, %struct.Node*** %2
%26 = load %struct.Node*, %struct.Node** %25
%27 = call i32 @find_variables(%struct.Node* %26, i8** %3)
%28 = load i8*, i8** %3
store i8* %28, i8** %4
br label %29
29: ; preds = %64, %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %67
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8 signext %36)
%38 = load i32, i32* @MAX_INPUT
%39 = sub nsw i32 %38, 1
%40 = load i32, i32* @stdin
%41 = call i32 @fgets(i8* %11, i32 %39, i32 %40)
%42 = call i32 @strlen(i8* %11)
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %11, i64 %44
store i8 0, i8* %45
%46 = call %struct.Node* @parse(i8* %11)
store %struct.Node* %46, %struct.Node** %7
%47 = load %struct.Node*, %struct.Node** %7
%48 = icmp eq %struct.Node* %47, null
br i1 %48, label %49, label %54
49: ; preds = %34
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i32 -1
store i8* %53, i8** %4
br label %64
54: ; preds = %34
%55 = load %struct.Node*, %struct.Node** %7
%56 = call i32 @reduce(%struct.Node* %55)
%57 = load i8*, i8** %4
%58 = load i8, i8* %57
%59 = load %struct.Node**, %struct.Node*** %2
%60 = load %struct.Node*, %struct.Node** %7
%61 = call i32 @replace(i8 signext %58, %struct.Node** %59, %struct.Node* %60)
%62 = load %struct.Node*, %struct.Node** %7
%63 = call i32 @delete_node(%struct.Node* %62)
br label %64
64: ; preds = %54, %49
%65 = load i8*, i8** %4
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %4
br label %29
67: ; preds = %29
%68 = load i8*, i8** %3
%69 = call i32 @free(i8* %68)
br label %12
70: ; preds = %12
%71 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.Node = type { i32 }
@MAX_INPUT = global i32 0
@.str = [7 x i8] c"calloc\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"value of variable %c: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"cannot create parse tree\0A\00"
define void @replace_variables(%struct.Node** %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i32, i32* @MAX_INPUT
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = load %struct.Node*, %struct.Node** %0
%9 = call i64 @has_variables(%struct.Node* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %60, label %11
11: ; preds = %1, %54
%12 = call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
store i8* %12, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = load %struct.Node*, %struct.Node** %0
%20 = call i32 @find_variables(%struct.Node* %19, i8** %2)
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %54, label %24
24: ; preds = %18, %47
%25 = phi i8 [ %50, %47 ], [ %22, %18 ]
%26 = phi i8* [ %49, %47 ], [ %21, %18 ]
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8 signext %25)
%28 = load i32, i32* @MAX_INPUT
%29 = add nsw i32 %28, -1
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %7, i32 %29, i32 %30)
%32 = call i32 @strlen(i8* %7)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %7, i64 %34
store i8 0, i8* %35
%36 = call %struct.Node* @parse(i8* %7)
%37 = icmp eq %struct.Node* %36, null
br i1 %37, label %38, label %42
38: ; preds = %24
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%41 = getelementptr inbounds i8, i8* %26, i64 -1
br label %47
42: ; preds = %24
%43 = call i32 @reduce(%struct.Node* %36)
%44 = load i8, i8* %26
%45 = call i32 @replace(i8 signext %44, %struct.Node** %0, %struct.Node* %36)
%46 = call i32 @delete_node(%struct.Node* %36)
br label %47
47: ; preds = %42, %38
%48 = phi i8* [ %41, %38 ], [ %26, %42 ]
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %52, label %24
52: ; preds = %47
%53 = load i8*, i8** %2
br label %54
54: ; preds = %52, %18
%55 = phi i8* [ %53, %52 ], [ %21, %18 ]
%56 = call i32 @free(i8* %55)
%57 = load %struct.Node*, %struct.Node** %0
%58 = call i64 @has_variables(%struct.Node* %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %11
60: ; preds = %54, %1
ret void
}