#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
void replaceVar(char *in, char *out) {
  char vars[100], command[100];
  FILE *file;
  FILE *f;
  if ((f = fopen("var", "r")) == NULL) {
    fprintf(stderr, "Error when open var files");
  }
  fscanf(f, "%[^\t]%*c%[^\n]%*c", vars, command);
  while (!feof(f)) {
    if (strcmp(in, vars) == 0) {
      file = popen(command, "r");
      fscanf(file, "%[^\n]%*c", out);
      pclose(file);
      break;
    }
    fscanf(f, "%[^\t]%*c%[^\n]%*c", vars, command);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<replaceVar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe61(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x100(%rbp)
cmp    $0x0,%rax
jne    11cc <replaceVar+0x4c>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x100(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0xf0(%rbp),%rcx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x100(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120d <replaceVar+0x8d>
jmp    128d <replaceVar+0x10d>
mov    -0x8(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1268 <replaceVar+0xe8>
lea    -0xf0(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0xf8(%rbp),%rdi
call   1040 <pclose@plt>
jmp    128d <replaceVar+0x10d>
mov    -0x100(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    -0xf0(%rbp),%rcx
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
jmp    11ec <replaceVar+0x6c>
mov    -0x100(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceVar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe62(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c7 <replaceVar+0x47>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1070 <fprintf@plt>
lea    0xe50(%rip),%rsi
lea    0x70(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    125f <replaceVar+0xdf>
lea    0x70(%rsp),%r12
lea    0xe26(%rip),%r13
mov    %rsp,%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1231 <replaceVar+0xb1>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1200 <replaceVar+0x80>
jmp    125f <replaceVar+0xdf>
lea    0xdca(%rip),%rsi
mov    %rsp,%rdi
call   1090 <popen@plt>
mov    %rax,%rbp
lea    0xddc(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <pclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"var\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error when open var files\00"
@.str.3 = [17 x i8] c"%[^\09]%*c%[^\0A]%*c\00"
@.str.4 = [9 x i8] c"%[^\0A]%*c\00"
define void @replaceVar(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %11, %2
%15 = load i32*, i32** %8
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %16, i8* %17)
br label %19
19: ; preds = %37, %14
%20 = load i32*, i32** %8
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %42
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%31 = call i32* @popen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %7
%32 = load i32*, i32** %7
%33 = load i8*, i8** %4
%34 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i32*, i32** %7
%36 = call i32 @pclose(i32* %35)
br label %42
37: ; preds = %24
%38 = load i32*, i32** %8
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%41 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %39, i8* %40)
br label %19
42: ; preds = %29, %19
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"var\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error when open var files\00"
@.str.3 = [17 x i8] c"%[^\09]%*c%[^\0A]%*c\00"
@.str.4 = [9 x i8] c"%[^\0A]%*c\00"
define void @replaceVar(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %9, %2
%13 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %6)
%14 = call i32 @feof(i32* %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %12, %23
%17 = call i64 @strcmp(i8* %0, i8* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%22 = call i32 @pclose(i32* %20)
br label %27
23: ; preds = %16
%24 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %6)
%25 = call i32 @feof(i32* %7)
%26 = icmp eq i32 %25, 0
br i1 %26, label %16, label %27
27: ; preds = %23, %12, %19
%28 = call i32 @fclose(i32* %7)
ret void
}