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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc < 2)
    return 1;
  char *c = argv[1];
  FILE *rfile, *wfile;
  wfile = fopen("program.txt", "w");
  if (wfile == NULL) {
    printf("Error!");
    exit(1);
  }
  time_t t;
  srand((unsigned)time(&t));
  fprintf(wfile, "%s", c);
  fclose(wfile);
  rfile = fopen("program.txt", "r");
  if (rfile == NULL) {
    printf("Error!");
    exit(1);
  }
  char ch;
  while ((ch = fgetc(rfile)) != EOF) {
    printf("%c", ch);
  }
  printf("\n");
  fclose(rfile);
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11ac <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    12b4 <main+0x134>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe41(%rip),%rdi
lea    0xe46(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f2 <main+0x72>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x2c(%rbp),%rdi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe04(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdda(%rip),%rdi
lea    0xdeb(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1259 <main+0xd9>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    125e <main+0xde>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x2d(%rbp)
movsbl %al,%eax
mov    0x2d74(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1296 <main+0x116>
movsbl -0x2d(%rbp),%esi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125e <main+0xde>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
cmp    $0x2,%edi
jl     1249 <main+0xb9>
mov    0x8(%rsi),%r14
lea    0xe53(%rip),%rdi
lea    0xe58(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1251 <main+0xc1>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe10(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1251 <main+0xc1>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2dd5(%rip),%r14
cmp    (%r14),%al
je     1235 <main+0xa5>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%al
jne    1220 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdb6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"program.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"Error!\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %55
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = call i64 @time(i32* %9)
%26 = trunc i64 %25 to i32
%27 = call i32 @srand(i32 %26)
%28 = load i32*, i32** %8
%29 = load i8*, i8** %6
%30 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
%33 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %33, i32** %7
%34 = load i32*, i32** %7
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %24
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %24
br label %40
40: ; preds = %47, %39
%41 = load i32*, i32** %7
%42 = call signext i8 @fgetc(i32* %41)
store i8 %42, i8* %10
%43 = sext i8 %42 to i32
%44 = load i8, i8* @EOF
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %43, %45
br i1 %46, label %47, label %51
47: ; preds = %40
%48 = load i8, i8* %10
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %49)
br label %40
51: ; preds = %40
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %51, %13
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [12 x i8] c"program.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"Error!\00"
@.str.4 = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %39, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %5
%14 = bitcast i32* %3 to i8*
%15 = call i64 @time(i32* %3)
%16 = trunc i64 %15 to i32
%17 = call i32 @srand(i32 %16)
%18 = call i32 @fputs(i8* %7, i32* %8)
%19 = call i32 @fclose(i32* %8)
%20 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %13
%23 = call signext i8 @fgetc(i32* %20)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %36, label %29
26: ; preds = %13
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %22, %29
%30 = phi i8 [ %33, %29 ], [ %23, %22 ]
%31 = sext i8 %30 to i32
%32 = call i32 @putchar(i32 %31)
%33 = call signext i8 @fgetc(i32* %20)
%34 = load i8, i8* @EOF
%35 = icmp eq i8 %33, %34
br i1 %35, label %36, label %29
36: ; preds = %29, %22
%37 = call i32 @putchar(i32 10)
%38 = call i32 @fclose(i32* %20)
br label %39
39: ; preds = %2, %36
%40 = phi i32 [ 0, %36 ], [ 1, %2 ]
ret i32 %40
}