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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
char *read_whole_textfile(char *);
char *replace_all(struct replace *, char *, char *);
int /*<<< orphan*/ replace_endall(struct replace *);
struct replace *replace_read(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ write_whole_textfile(char *, char *);
int main(int argc, char *argv[]) {
  struct replace *r = replace_read(stdin);
  int i;
  if (r == NULL)
    return EXIT_FAILURE;
  for (i = 1; i < argc; i++) {
    char *cont = read_whole_textfile(argv[i]), *ed;
    ed = replace_all(r, argv[i], cont);
    if (ed != NULL)
      write_whole_textfile(argv[i], ed);
    free(cont);
    free(ed);
  }
  replace_endall(r);
  return EXIT_SUCCESS;
  (void)argc;
  (void)argv;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1050 <replace_read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <main+0x44>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123e <main+0xde>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1229 <main+0xc9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <read_whole_textfile@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <replace_all@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1209 <main+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <write_whole_textfile@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ab <main+0x4b>
mov    -0x18(%rbp),%rdi
call   1030 <replace_endall@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1050 <replace_read@plt>
test   %rax,%rax
je     11fb <main+0x9b>
mov    %rax,%r14
cmp    $0x2,%ebx
jl     11ea <main+0x8a>
mov    %ebx,%r13d
mov    $0x1,%ebp
jmp    11b9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11ea <main+0x8a>
mov    (%r15,%rbp,8),%rdi
call   1080 <read_whole_textfile@plt>
mov    %rax,%r12
mov    (%r15,%rbp,8),%rsi
mov    %r14,%rdi
mov    %rax,%rdx
call   1060 <replace_all@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a0 <main+0x40>
mov    (%r15,%rbp,8),%rdi
mov    %rbx,%rsi
call   1070 <write_whole_textfile@plt>
jmp    11a0 <main+0x40>
mov    %r14,%rdi
call   1030 <replace_endall@plt>
mov    0x2dd7(%rip),%rax
jmp    1202 <main+0xa2>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.replace = type { i32 }
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.replace*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @stdin
%11 = call %struct.replace* @replace_read(i32 %10)
store %struct.replace* %11, %struct.replace** %6
%12 = load %struct.replace*, %struct.replace** %6
%13 = icmp eq %struct.replace* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %58
16: ; preds = %2
store i32 1, i32* %7
br label %17
17: ; preds = %51, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %54
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i8* @read_whole_textfile(i8* %26)
store i8* %27, i8** %8
%28 = load %struct.replace*, %struct.replace** %6
%29 = load i8**, i8*** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i8*, i8** %8
%35 = call i8* @replace_all(%struct.replace* %28, i8* %33, i8* %34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %46
38: ; preds = %21
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = load i8*, i8** %9
%45 = call i32 @write_whole_textfile(i8* %43, i8* %44)
br label %46
46: ; preds = %38, %21
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %9
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %46
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %17
54: ; preds = %17
%55 = load %struct.replace*, %struct.replace** %6
%56 = call i32 @replace_endall(%struct.replace* %55)
%57 = load i32, i32* @EXIT_SUCCESS
store i32 %57, i32* %3
br label %58
58: ; preds = %54, %14
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.replace = type { i32 }
@stdin = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stdin
%4 = tail call %struct.replace* @replace_read(i32 %3)
%5 = icmp eq %struct.replace* %4, null
br i1 %5, label %28, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %26
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %21
%11 = phi i64 [ 1, %8 ], [ %24, %21 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i8* @read_whole_textfile(i8* %13)
%15 = load i8*, i8** %12
%16 = tail call i8* @replace_all(%struct.replace* %4, i8* %15, i8* %14)
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %10
%19 = load i8*, i8** %12
%20 = tail call i32 @write_whole_textfile(i8* %19, i8* %16)
br label %21
21: ; preds = %18, %10
%22 = tail call i32 @free(i8* %14)
%23 = tail call i32 @free(i8* %16)
%24 = add nuw nsw i64 %11, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %26, label %10
26: ; preds = %21, %6
%27 = tail call i32 @replace_endall(%struct.replace* %4)
br label %28
28: ; preds = %2, %26
%29 = phi i32* [ @EXIT_SUCCESS, %26 ], [ @EXIT_FAILURE, %2 ]
%30 = load i32, i32* %29
ret i32 %30
}