#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  FILE *file_in, *file_out;
  char line_in_buf[256], line_out_buf[2 * 256];
  if ((file_in = fopen("tmp1_file", "r")) == NULL) {
    fprintf(stderr, "Can not open input file: <<tmp1_file>>\n");
    exit(1);
  }
  if ((file_out = fopen("tmp2_file", "w")) == NULL) {
    fprintf(stderr, "Can not open output file: <<tmp2_file>>\n");
    fclose(file_in);
    exit(1);
  }
  while (fgets(line_in_buf, 256, file_in) != NULL) {
    if (line_in_buf[0] != ' ') {
      strcpy(line_out_buf, argv[1]);
      strcat(line_out_buf, line_in_buf);
    } else {
      strcpy(line_out_buf, line_in_buf);
    }
    fputs(line_out_buf, file_out);
  }
  fclose(file_in);
  fclose(file_out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d9 <main+0x59>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe54(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1222 <main+0xa2>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1227 <main+0xa7>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12aa <main+0x12a>
movsbl -0x120(%rbp),%eax
cmp    $0x20,%eax
je     1282 <main+0x102>
lea    -0x320(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x320(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1090 <strcat@plt>
jmp    1295 <main+0x115>
lea    -0x320(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x320(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <fputs@plt>
jmp    1227 <main+0xa7>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x320,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x300,%rsp
mov    %rsi,%r14
lea    0xe66(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     126d <main+0xed>
mov    %rax,%r15
lea    0xe7b(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     128c <main+0x10c>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     124a <main+0xca>
lea    0x100(%rsp),%rbx
mov    %rsp,%r13
jmp    122b <main+0xab>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <fputs@plt>
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     124a <main+0xca>
cmpb   $0x20,(%rsp)
je     1200 <main+0x80>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strcat@plt>
jmp    120b <main+0x8b>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x300,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"tmp1_file\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Can not open input file: <<tmp1_file>>\0A\00"
@.str.3 = [10 x i8] c"tmp2_file\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [41 x i8] c"Can not open output file: <<tmp2_file>>\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 [256 x i8]
%9 = alloca [512 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 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %17, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
br label %26
26: ; preds = %49, %25
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %6
%29 = call i32* @fgets(i8* %27, i32 256, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %53
31: ; preds = %26
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 32
br i1 %35, label %36, label %45
36: ; preds = %31
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcpy(i8* %37, i8* %40)
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%44 = call i32 @strcat(i8* %42, i8* %43)
br label %49
45: ; preds = %31
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%48 = call i32 @strcpy(i8* %46, i8* %47)
br label %49
49: ; preds = %45, %36
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%51 = load i32*, i32** %7
%52 = call i32 @fputs(i8* %50, i32* %51)
br label %26
53: ; preds = %26
%54 = load i32*, i32** %6
%55 = call i32 @fclose(i32* %54)
%56 = load i32*, i32** %7
%57 = call i32 @fclose(i32* %56)
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [10 x i8] c"tmp1_file\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Can not open input file: <<tmp1_file>>\0A\00"
@.str.3 = [10 x i8] c"tmp2_file\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [41 x i8] c"Can not open output file: <<tmp2_file>>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = call i32* @fgets(i8* %5, i32 256, i32* %7)
%18 = icmp eq i32* %17, null
br i1 %18, label %39, label %19
19: ; preds = %16
%20 = getelementptr inbounds i8*, i8** %1, i64 1
br label %26
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%24 = tail call i32 @fclose(i32* %7)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %19, %35
%27 = load i8, i8* %5
%28 = icmp eq i8 %27, 32
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i8*, i8** %20
%31 = call i32 @strcpy(i8* %6, i8* %30)
%32 = call i32 @strcat(i8* %6, i8* %5)
br label %35
33: ; preds = %26
%34 = call i32 @strcpy(i8* %6, i8* %5)
br label %35
35: ; preds = %33, %29
%36 = call i32 @fputs(i8* %6, i32* %14)
%37 = call i32* @fgets(i8* %5, i32 256, i32* %7)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %26
39: ; preds = %35, %16
%40 = call i32 @fclose(i32* %7)
%41 = call i32 @fclose(i32* %14)
ret i32 0
}