#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int getchar();
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv, char **envp) {
  const char *filename;
  FILE *file;
  int c;
  if (argc != 2) {
    fprintf(stderr, "%s: Please supply the name of the file to edit\n",
            argv[0]);
    return 0;
  }
  filename = argv[1];
  file = fopen(filename, "w");
  while ((c = getchar()) != EOF) {
    putchar(c);
    fputc(c, file);
  }
  fclose(file);
  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)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ac <main+0x4c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe65(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    120e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%eax
je     11fe <main+0x9e>
mov    -0x2c(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1050 <fputc@plt>
jmp    11cc <main+0x6c>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11c9 <main+0x69>
mov    0x8(%rsi),%rdi
lea    0xebc(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e5e(%rip),%r14
cmp    (%r14),%eax
je     11bf <main+0x5f>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebp
cmp    (%r14),%eax
jne    11a0 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11e1 <main+0x81>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe24(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [48 x i8] c"%s: Please supply the name of the file to edit\0A\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 0, i32* %4
br label %38
19: ; preds = %3
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %9
br label %25
25: ; preds = %29, %19
%26 = call i32 (...) @getchar()
store i32 %26, i32* %10
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32, i32* %10
%31 = call i32 @putchar(i32 %30)
%32 = load i32, i32* %10
%33 = load i32*, i32** %9
%34 = call i32 @fputc(i32 %32, i32* %33)
br label %25
35: ; preds = %25
%36 = load i32*, i32** %9
%37 = call i32 @fclose(i32* %36)
store i32 0, i32* %4
br label %38
38: ; preds = %35, %13
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [48 x i8] c"%s: Please supply the name of the file to edit\0A\00"
@.str.1 = [2 x i8] c"w\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %25
9: ; preds = %3
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 (...) @getchar()
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %23, label %16
16: ; preds = %9, %16
%17 = phi i32 [ %20, %16 ], [ %13, %9 ]
%18 = tail call i32 @putchar(i32 %17)
%19 = tail call i32 @fputc(i32 %17, i32* %12)
%20 = tail call i32 (...) @getchar()
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %16
23: ; preds = %16, %9
%24 = tail call i32 @fclose(i32* %12)
br label %25
25: ; preds = %23, %5
ret i32 0
}