#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 *, 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(void) {
  FILE *filePtr;
  FILE *tempFilePtr;
  int c;
  char fileName[30];
  printf("This program changes tabs to spaces.\n"
         "Enter a file to be modified: ");
  scanf("%29s", fileName);
  if ((filePtr = fopen(fileName, "r+")) != NULL) {
    if ((tempFilePtr = tmpfile()) != NULL) {
      printf("\nThe file before modification is:\n");
      while ((c = getc(filePtr)) != EOF) {
        putchar(c);
        putc(c == '\t' ? ' ' : c, 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);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe9b(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     12ab <main+0x12b>
mov    $0x0,%al
call   1060 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1298 <main+0x118>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
je     123f <main+0xbf>
mov    -0x1c(%rbp),%edi
call   1030 <putchar@plt>
cmpl   $0x9,-0x1c(%rbp)
jne    1228 <main+0xa8>
mov    $0x20,%eax
mov    %eax,-0x44(%rbp)
jmp    122e <main+0xae>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <putc@plt>
jmp    11ee <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d76(%rip),%rcx
cmp    (%rcx),%eax
je     1293 <main+0x113>
mov    -0x1c(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <putc@plt>
jmp    125f <main+0xdf>
jmp    12a6 <main+0x126>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12bd <main+0x13d>
lea    -0x40(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe92(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a2 <main+0x112>
mov    %rax,%r14
xor    %eax,%eax
call   1070 <tmpfile@plt>
test   %rax,%rax
je     12b5 <main+0x125>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    0x2de3(%rip),%r15
cmp    (%r15),%eax
je     1247 <main+0xb7>
mov    %eax,%ebp
mov    $0x20,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <putchar@plt>
cmp    $0x9,%ebp
cmove  %r12d,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <putc@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1220 <main+0x90>
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %r14,%rdi
call   1060 <rewind@plt>
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%eax
je     12c1 <main+0x131>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
jne    1280 <main+0xf0>
jmp    12c1 <main+0x131>
lea    0xda2(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12c1 <main+0x131>
lea    0xda2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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