#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 *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ *tmpfile();
int main(int argc, char *argv[]) {
  FILE *filePtr, *tempFilePtr;
  int c;
  char fileName[30];
  printf("This program adds a space after every chararcter.\n"
         "Enter a file to be modified: ");
  scanf("%s", fileName);
  if ((filePtr = fopen(fileName, "r+")) != NULL)
    if ((tempFilePtr = tmpfile()) != NULL) {
      while ((c = getc(filePtr)) != EOF) {
        putchar(c);
        putc(c, tempFilePtr);
        putc(' ', tempFilePtr);
      }
      rewind(tempFilePtr);
      rewind(filePtr);
      printf("\n\nThe file after modification is:\n");
      while ((c = getc(tempFilePtr)) != EOF) {
        putchar(c);
        putc(c, filePtr);
      }
    } else
      printf("Unable to open temporary file\n");
  else
    printf("Unable to open %s\n", fileName);
  fclose(tempFilePtr);
  fclose(filePtr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe91(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12aa <main+0x11a>
mov    $0x0,%al
call   1070 <tmpfile@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1297 <main+0x107>
jmp    11fc <main+0x6c>
mov    -0x18(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%eax
je     123e <main+0xae>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <putc@plt>
mov    -0x20(%rbp),%rsi
mov    $0x20,%edi
call   1080 <putc@plt>
jmp    11fc <main+0x6c>
mov    -0x20(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x18(%rbp),%rdi
call   1060 <rewind@plt>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d77(%rip),%rcx
cmp    (%rcx),%eax
je     1292 <main+0x102>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <putc@plt>
jmp    125e <main+0xce>
jmp    12a5 <main+0x115>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12bc <main+0x12c>
lea    -0x50(%rbp),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe4f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe91(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10a0 <scanf@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12bb <main+0x11b>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <tmpfile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1292 <main+0xf2>
mov    %r14,%rdi
call   10c0 <getc@plt>
mov    0x2de1(%rip),%r15
cmp    (%r15),%eax
je     123d <main+0x9d>
mov    %eax,%ebp
xchg   %ax,%ax
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <putc@plt>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1090 <putc@plt>
mov    %r14,%rdi
call   10c0 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1210 <main+0x70>
mov    %rbx,%rdi
call   1070 <rewind@plt>
mov    %r14,%rdi
call   1070 <rewind@plt>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
cmp    (%r15),%eax
je     129e <main+0xfe>
mov    %eax,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <putc@plt>
mov    %rbx,%rdi
call   10c0 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1270 <main+0xd0>
jmp    129e <main+0xfe>
lea    0xdd0(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd94(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>

LLVM IR (-O0):
@.str = [80 x i8] c"This program adds a space after every chararcter.\0AEnter a file to be modified: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"r+\00"
@EOF = global i32 0
@.str.3 = [35 x i8] c"\0A\0AThe file after modification is:\0A\00"
@.str.4 = [31 x i8] c"Unable to open temporary file\0A\00"
@.str.5 = [19 x i8] c"Unable to open %s\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 i32
%9 = alloca [30 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %54
16: ; preds = %2
%17 = call i32* (...) @tmpfile()
store i32* %17, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %51
19: ; preds = %16
br label %20
20: ; preds = %25, %19
%21 = load i32*, i32** %6
%22 = call i32 @getc(i32* %21)
store i32 %22, i32* %8
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* %8
%27 = call i32 @putchar(i32 %26)
%28 = load i32, i32* %8
%29 = load i32*, i32** %7
%30 = call i32 @putc(i32 %28, i32* %29)
%31 = load i32*, i32** %7
%32 = call i32 @putc(i32 32, i32* %31)
br label %20
33: ; preds = %20
%34 = load i32*, i32** %7
%35 = call i32 @rewind(i32* %34)
%36 = load i32*, i32** %6
%37 = call i32 @rewind(i32* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %44, %33
%40 = load i32*, i32** %7
%41 = call i32 @getc(i32* %40)
store i32 %41, i32* %8
%42 = load i32, i32* @EOF
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %50
44: ; preds = %39
%45 = load i32, i32* %8
%46 = call i32 @putchar(i32 %45)
%47 = load i32, i32* %8
%48 = load i32*, i32** %6
%49 = call i32 @putc(i32 %47, i32* %48)
br label %39
50: ; preds = %39
br label %53
51: ; preds = %16
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %50
br label %57
54: ; preds = %2
%55 = getelementptr inbounds [30 x i8], [30 x i8]* %9, i64 0, i64 0
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %54, %53
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [80 x i8] c"This program adds a space after every chararcter.\0AEnter a file to be modified: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"r+\00"
@EOF = global i32 0
@.str.5 = [19 x i8] c"Unable to open %s\0A\00"
@str = [30 x i8] c"Unable to open temporary file\00"
@str.6 = [34 x i8] c"\0A\0AThe file after modification is:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %40, label %9
9: ; preds = %2
%10 = call i32* (...) @tmpfile()
%11 = icmp eq i32* %10, null
br i1 %11, label %38, label %12
12: ; preds = %9
%13 = call i32 @getc(i32* %7)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %24, label %16
16: ; preds = %12, %16
%17 = phi i32 [ %21, %16 ], [ %13, %12 ]
%18 = call i32 @putchar(i32 %17)
%19 = call i32 @putc(i32 %17, i32* %10)
%20 = call i32 @putc(i32 32, i32* %10)
%21 = call i32 @getc(i32* %7)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %16
24: ; preds = %16, %12
%25 = call i32 @rewind(i32* %10)
%26 = call i32 @rewind(i32* %7)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0))
%28 = call i32 @getc(i32* %10)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %42, label %31
31: ; preds = %24, %31
%32 = phi i32 [ %35, %31 ], [ %28, %24 ]
%33 = call i32 @putchar(i32 %32)
%34 = call i32 @putc(i32 %32, i32* %7)
%35 = call i32 @getc(i32* %10)
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %42, label %31
38: ; preds = %9
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %42
40: ; preds = %2
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %4)
unreachable
42: ; preds = %31, %24, %38
%43 = call i32 @fclose(i32* %10)
%44 = call i32 @fclose(i32* %7)
ret i32 0
}