#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*/ *fopen(char const *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *tmpfile();
int main(int argc, char const *argv[]) {
  FILE *filePtr;
  FILE *tempPtr;
  int c;
  int temp;
  if ((filePtr = fopen(argv[1], "r+")) != NULL) {
    if ((tempPtr = tmpfile()) != NULL) {
      while ((c = getc(filePtr)) != EOF) {
        putchar(c);
        putc(c, tempPtr);
        putc(' ', tempPtr);
      }
      rewind(tempPtr);
      rewind(filePtr);
      printf("%s\n", "New:");
      while ((c = getc(tempPtr)) != EOF) {
        putchar(c);
        putc(c, filePtr);
      }
    }
  }
  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    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1267 <main+0xf7>
mov    $0x0,%al
call   1060 <tmpfile@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1262 <main+0xf2>
jmp    11c2 <main+0x52>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%eax
je     1204 <main+0x94>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <putc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x20,%edi
call   1070 <putc@plt>
jmp    11c2 <main+0x52>
mov    -0x20(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
lea    0xde6(%rip),%rdi
lea    0xde3(%rip),%rsi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dac(%rip),%rcx
cmp    (%rcx),%eax
je     125d <main+0xed>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <putc@plt>
jmp    1229 <main+0xb9>
jmp    1262 <main+0xf2>
jmp    1267 <main+0xf7>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1240 <main+0xd0>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <tmpfile@plt>
test   %rax,%rax
je     1240 <main+0xd0>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <getc@plt>
mov    0x2e33(%rip),%r15
cmp    (%r15),%eax
je     11ed <main+0x7d>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <putc@plt>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1070 <putc@plt>
mov    %r14,%rdi
call   1090 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    11c0 <main+0x50>
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r14,%rdi
call   1050 <rewind@plt>
lea    0xdff(%rip),%rdi
lea    0xdfc(%rip),%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r15),%eax
je     1240 <main+0xd0>
mov    %eax,%ebp
nop
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <putc@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1220 <main+0xb0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"New:\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 i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %51
15: ; preds = %2
%16 = call i32* (...) @tmpfile()
store i32* %16, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %50
18: ; preds = %15
br label %19
19: ; preds = %24, %18
%20 = load i32*, i32** %6
%21 = call i32 @getc(i32* %20)
store i32 %21, i32* %8
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i32, i32* %8
%26 = call i32 @putchar(i32 %25)
%27 = load i32, i32* %8
%28 = load i32*, i32** %7
%29 = call i32 @putc(i32 %27, i32* %28)
%30 = load i32*, i32** %7
%31 = call i32 @putc(i32 32, i32* %30)
br label %19
32: ; preds = %19
%33 = load i32*, i32** %7
%34 = call i32 @rewind(i32* %33)
%35 = load i32*, i32** %6
%36 = call i32 @rewind(i32* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %43, %32
%39 = load i32*, i32** %7
%40 = call i32 @getc(i32* %39)
store i32 %40, i32* %8
%41 = load i32, i32* @EOF
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* %8
%45 = call i32 @putchar(i32 %44)
%46 = load i32, i32* %8
%47 = load i32*, i32** %6
%48 = call i32 @putc(i32 %46, i32* %47)
br label %38
49: ; preds = %38
br label %50
50: ; preds = %49, %15
br label %51
51: ; preds = %50, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@EOF = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"New:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %36, label %7
7: ; preds = %2
%8 = tail call i32* (...) @tmpfile()
%9 = icmp eq i32* %8, null
br i1 %9, label %36, label %10
10: ; preds = %7
%11 = tail call i32 @getc(i32* %5)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %22, label %14
14: ; preds = %10, %14
%15 = phi i32 [ %19, %14 ], [ %11, %10 ]
%16 = tail call i32 @putchar(i32 %15)
%17 = tail call i32 @putc(i32 %15, i32* %8)
%18 = tail call i32 @putc(i32 32, i32* %8)
%19 = tail call i32 @getc(i32* %5)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %14
22: ; preds = %14, %10
%23 = tail call i32 @rewind(i32* %8)
%24 = tail call i32 @rewind(i32* %5)
%25 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @getc(i32* %8)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %36, label %29
29: ; preds = %22, %29
%30 = phi i32 [ %33, %29 ], [ %26, %22 ]
%31 = tail call i32 @putchar(i32 %30)
%32 = tail call i32 @putc(i32 %30, i32* %5)
%33 = tail call i32 @getc(i32* %8)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %29
36: ; preds = %29, %22, %7, %2
ret i32 0
}