#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 /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
void detab_file(const char *filename, const int s_num) {
  FILE *file;
  char in_buffer[32];
  int i, j, bytes;
  if ((file = fopen(filename, "r")) == NULL) {
    printf("Error: file couldn't be opened!\n");
    exit(-1);
  }
  j = 0;
  while (1) {
    bytes = fread(in_buffer, sizeof(char), 32, file);
    if (ferror(file)) {
      printf("Error while reading file!\n");
      exit(-1);
    }
    for (i = 0; i < bytes; i++)
      if (in_buffer[i] == '\t')
        for (j = 0; j < s_num; j++)
          putchar(' ');
      else
        putchar(in_buffer[i]);
    if (feof(file))
      break;
  }
  if (fclose(file)) {
    printf("Error while attempting to close file!\n");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<detab_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c3 <detab_file+0x43>
lea    0xe4e(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1050 <fread@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     120d <detab_file+0x8d>
lea    0xe25(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1283 <detab_file+0x103>
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x9,%eax
jne    1262 <detab_file+0xe2>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    125d <detab_file+0xdd>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1239 <detab_file+0xb9>
jmp    1270 <detab_file+0xf0>
movslq -0x44(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
jmp    1275 <detab_file+0xf5>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1214 <detab_file+0x94>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     129b <detab_file+0x11b>
jmp    12a0 <detab_file+0x120>
jmp    11ca <detab_file+0x4a>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     12c9 <detab_file+0x149>
lea    0xd84(%rip),%rdi
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detab_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%r12d
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1253 <detab_file+0xd3>
mov    %rax,%r14
mov    %rsp,%r15
jmp    11bd <detab_file+0x3d>
xchg   %ax,%ax
mov    %r14,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    1221 <detab_file+0xa1>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %r14,%rcx
call   1060 <fread@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
jne    123d <detab_file+0xbd>
test   %ebp,%ebp
jle    11b0 <detab_file+0x30>
mov    %ebp,%r13d
xor    %ebx,%ebx
jmp    1201 <detab_file+0x81>
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
je     11b0 <detab_file+0x30>
mov    (%rsp,%rbx,1),%al
cmp    $0x9,%al
jne    11f0 <detab_file+0x70>
test   %r12d,%r12d
jle    11f8 <detab_file+0x78>
mov    %r12d,%ebp
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1210 <detab_file+0x90>
jmp    11f8 <detab_file+0x78>
mov    %r14,%rdi
call   1070 <fclose@plt>
test   %rax,%rax
jne    125c <detab_file+0xdc>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde4(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xde8(%rip),%rdi
jmp    1244 <detab_file+0xc4>
lea    0xd9f(%rip),%rdi
jmp    1244 <detab_file+0xc4>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [33 x i8] c"Error: file couldn't be opened!\0A\00"
@.str.2 = [27 x i8] c"Error while reading file!\0A\00"
@.str.3 = [39 x i8] c"Error while attempting to close file!\0A\00"
define void @detab_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
store i32 0, i32* %8
br label %17
17: ; preds = %16, %65
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %5
%20 = call i32 @fread(i8* %18, i32 1, i32 32, i32* %19)
store i32 %20, i32* %9
%21 = load i32*, i32** %5
%22 = call i64 @ferror(i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %17
store i32 0, i32* %7
br label %28
28: ; preds = %57, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %9
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %60
32: ; preds = %28
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 9
br i1 %38, label %39, label %50
39: ; preds = %32
store i32 0, i32* %8
br label %40
40: ; preds = %46, %39
%41 = load i32, i32* %8
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = call i32 @putchar(i8 signext 32)
br label %46
46: ; preds = %44
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %40
49: ; preds = %40
br label %56
50: ; preds = %32
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @putchar(i8 signext %54)
br label %56
56: ; preds = %50, %49
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %28
60: ; preds = %28
%61 = load i32*, i32** %5
%62 = call i64 @feof(i32* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
br label %66
65: ; preds = %60
br label %17
66: ; preds = %64
%67 = load i32*, i32** %5
%68 = call i64 @fclose(i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66
%71 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%72 = call i32 @exit(i32 -1)
unreachable
73: ; preds = %66
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@str = [38 x i8] c"Error while attempting to close file!\00"
@str.4 = [26 x i8] c"Error while reading file!\00"
@str.5 = [32 x i8] c"Error: file couldn't be opened!\00"
define void @detab_file(i8* nocapture %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = icmp sgt i32 %1, 0
br label %12
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %7, %39
%13 = call i32 @fread(i8* %4, i32 1, i32 32, i32* %5)
%14 = tail call i64 @ferror(i32* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = icmp sgt i32 %13, 0
br i1 %17, label %18, label %39
18: ; preds = %16
%19 = zext i32 %13 to i64
br label %23
20: ; preds = %12
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %18, %36
%24 = phi i64 [ 0, %18 ], [ %37, %36 ]
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 9
br i1 %27, label %28, label %34
28: ; preds = %23
br i1 %8, label %29, label %36
29: ; preds = %28, %29
%30 = phi i32 [ %32, %29 ], [ 0, %28 ]
%31 = tail call i32 @putchar(i8 signext 32)
%32 = add nuw nsw i32 %30, 1
%33 = icmp eq i32 %32, %1
br i1 %33, label %36, label %29
34: ; preds = %23
%35 = tail call i32 @putchar(i8 signext %26)
br label %36
36: ; preds = %29, %28, %34
%37 = add nuw nsw i64 %24, 1
%38 = icmp eq i64 %37, %19
br i1 %38, label %39, label %23
39: ; preds = %36, %16
%40 = tail call i64 @feof(i32* %5)
%41 = icmp eq i64 %40, 0
br i1 %41, label %12, label %42
42: ; preds = %39
%43 = tail call i64 @fclose(i32* %5)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%47 = tail call i32 @exit(i32 -1)
unreachable
48: ; preds = %42
ret void
}