#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 */
scalar_t__ EOF;
int /*<<< orphan*/ expand(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  in = fopen("input.dat", "r");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  out = fopen("output.dat", "w");
  if (out == NULL) {
    perror("output.dat");
    return 1;
  }
  char s1[128], s2[128];
  while (fscanf(in, "%s", s1) != EOF) {
    expand(s1, s2);
    fprintf(out, "expansion of '%s' is '%s'\n", s1, s2);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <main+0x53>
lea    0xe5e(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
lea    0xe52(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ed <main+0x8d>
lea    0xe30(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
jmp    11f2 <main+0x92>
mov    -0x18(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe15(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2dd8(%rip),%rcx
cmp    (%rcx),%rax
je     124f <main+0xef>
lea    -0xa0(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1080 <expand@plt>
mov    -0x20(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    -0x120(%rbp),%rcx
lea    0xdd7(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f2 <main+0x92>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xd8>
mov    %rax,%r14
lea    0xe75(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1241 <main+0xe1>
mov    %rax,%r15
lea    0xe63(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
mov    0x2e20(%rip),%r13
cmp    0x0(%r13),%rax
je     1214 <main+0xb4>
mov    %rsp,%rbx
lea    0x80(%rsp),%r12
lea    0xe39(%rip),%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <expand@plt>
mov    %r15,%rdi
lea    0xe27(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%r13),%rax
jne    11e0 <main+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc1(%rip),%rdi
jmp    1248 <main+0xe8>
lea    0xdc4(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    1226 <main+0xc6>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [27 x i8] c"expansion of '%s' is '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [128 x i8]
%9 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %41
15: ; preds = %2
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %41
21: ; preds = %15
br label %22
22: ; preds = %28, %21
%23 = load i32*, i32** %6
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%25 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = load i64, i64* @EOF
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %36
28: ; preds = %22
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%31 = call i32 @expand(i8* %29, i8* %30)
%32 = load i32*, i32** %7
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%35 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %33, i8* %34)
br label %22
36: ; preds = %22
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %3
br label %41
41: ; preds = %36, %19, %13
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.5 = [27 x i8] c"expansion of '%s' is '%s'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %29
9: ; preds = %2
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %29
14: ; preds = %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%17 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %26, label %20
20: ; preds = %14, %20
%21 = call i32 @expand(i8* %15, i8* %16)
%22 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %15, i8* %16)
%23 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %20
26: ; preds = %20, %14
%27 = call i32 @fclose(i32* %5)
%28 = call i32 @fclose(i32* %10)
br label %29
29: ; preds = %26, %12, %7
%30 = phi i32 [ 1, %7 ], [ 1, %12 ], [ 0, %26 ]
ret i32 %30
}