#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  char ch;
  int nb;
  int pos;
  FILE *in, *out;
  in = fopen("input.dat", "r");
  if (in == NULL) {
    perror("input.dat");
    return 1;
  }
  out = fopen("output.dat", "w");
  nb = 0;
  pos = 0;
  while ((ch = fgetc(in)) != EOF) {
    if (ch == '\t') {
      nb = 8 - pos % 8;
      while (nb > 0) {
        fputc(' ', out);
        pos++;
        nb--;
      }
    } else if (ch == '\n') {
      fputc('\n', out);
      pos = 0;
    } else {
      fputc(ch, out);
      pos++;
    }
  }
  fclose(in);
  fclose(out);
  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)
lea    0xe93(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a0 <main+0x50>
lea    0xe71(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    129e <main+0x14e>
lea    0xe65(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e0d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1285 <main+0x135>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
jne    123c <main+0xec>
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x8,%eax
sub    %edx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1237 <main+0xe7>
mov    -0x30(%rbp),%rsi
mov    $0x20,%edi
call   1050 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1208 <main+0xb8>
jmp    1280 <main+0x130>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    1263 <main+0x113>
mov    -0x30(%rbp),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
movl   $0x0,-0x1c(%rbp)
jmp    127b <main+0x12b>
mov    -0x11(%rbp),%al
mov    -0x30(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1280 <main+0x130>
jmp    11c5 <main+0x75>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%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   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1252 <main+0x102>
mov    %rax,%r14
lea    0xe8e(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e4c(%rip),%r15
cmp    (%r15),%al
jne    11bc <main+0x6c>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
jmp    11ec <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r12d
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
je     11a1 <main+0x51>
cmp    $0xa,%al
je     1240 <main+0xf0>
cmp    $0x9,%al
jne    11d0 <main+0x80>
lea    0x7(%r12),%eax
test   %r12d,%r12d
cmovns %r12d,%eax
and    $0xfffffff8,%eax
mov    %r12d,%ebp
sub    %eax,%ebp
mov    %eax,%r12d
add    $0x8,%r12d
add    $0xfffffff8,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
inc    %ebp
jne    1220 <main+0xd0>
jmp    11df <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
xor    %r12d,%r12d
jmp    11df <main+0x8f>
lea    0xda7(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11b3 <main+0x63>

LLVM IR (-O0):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %64
16: ; preds = %2
%17 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %17, i32** %10
store i32 0, i32* %7
store i32 0, i32* %8
br label %18
18: ; preds = %58, %16
%19 = load i32*, i32** %9
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %6
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %59
25: ; preds = %18
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 9
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load i32, i32* %8
%31 = srem i32 %30, 8
%32 = sub nsw i32 8, %31
store i32 %32, i32* %7
br label %33
33: ; preds = %36, %29
%34 = load i32, i32* %7
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i32*, i32** %10
%38 = call i32 @fputc(i8 signext 32, i32* %37)
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
%41 = load i32, i32* %7
%42 = add nsw i32 %41, -1
store i32 %42, i32* %7
br label %33
43: ; preds = %33
br label %58
44: ; preds = %25
%45 = load i8, i8* %6
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32*, i32** %10
%50 = call i32 @fputc(i8 signext 10, i32* %49)
store i32 0, i32* %8
br label %57
51: ; preds = %44
%52 = load i8, i8* %6
%53 = load i32*, i32** %10
%54 = call i32 @fputc(i8 signext %52, i32* %53)
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %57
57: ; preds = %51, %48
br label %58
58: ; preds = %57, %43
br label %18
59: ; preds = %18
%60 = load i32*, i32** %9
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %10
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %59, %14
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.dat\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %37
7: ; preds = %2
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call signext i8 @fgetc(i32* %3)
%10 = load i8, i8* @EOF
%11 = icmp eq i8 %9, %10
br i1 %11, label %34, label %12
12: ; preds = %7, %29
%13 = phi i8 [ %31, %29 ], [ %9, %7 ]
%14 = phi i32 [ %30, %29 ], [ 0, %7 ]
switch i8 %13, label %26 [
i8 9, label %15
i8 10, label %24
]
15: ; preds = %12
%16 = srem i32 %14, 8
%17 = add i32 %14, 8
%18 = sub i32 %17, %16
br label %19
19: ; preds = %15, %19
%20 = phi i32 [ %22, %19 ], [ %14, %15 ]
%21 = tail call i32 @fputc(i8 signext 32, i32* %8)
%22 = add i32 %20, 1
%23 = icmp eq i32 %22, %18
br i1 %23, label %29, label %19
24: ; preds = %12
%25 = tail call i32 @fputc(i8 signext 10, i32* %8)
br label %29
26: ; preds = %12
%27 = tail call i32 @fputc(i8 signext %13, i32* %8)
%28 = add nsw i32 %14, 1
br label %29
29: ; preds = %19, %24, %26
%30 = phi i32 [ 0, %24 ], [ %28, %26 ], [ %18, %19 ]
%31 = tail call signext i8 @fgetc(i32* %3)
%32 = load i8, i8* @EOF
%33 = icmp eq i8 %31, %32
br i1 %33, label %34, label %12
34: ; preds = %29, %7
%35 = tail call i32 @fclose(i32* %3)
%36 = tail call i32 @fclose(i32* %8)
br label %37
37: ; preds = %34, %5
%38 = phi i32 [ 1, %5 ], [ 0, %34 ]
ret i32 %38
}