#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*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int sfd_filesize(int /*<<< orphan*/ *);
int sfd_fix_indentation(char *fname) {
  FILE *f = fopen(fname, "rb");
  if (f != NULL) {
    char c, *buffer;
    int i = 0, tabs = 0, size = sfd_filesize(f);
    while ((c = fgetc(f)) != EOF)
      if (c == '\t')
        tabs++;
    buffer = malloc(size + (tabs * 4) + 1);
    rewind(f);
    while ((c = fgetc(f)) != EOF) {
      if (c == '\t') {
        buffer[i++] = ' ';
        buffer[i++] = ' ';
        buffer[i++] = ' ';
        buffer[i++] = ' ';
      } else
        buffer[i++] = c;
    }
    buffer[i] = '\0';
    fclose(f);
    remove(fname);
    if ((f = fopen(fname, "w+")) != NULL) {
      fprintf(f, "%s", buffer);
      free(buffer);
      fclose(f);
      return 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<sfd_fix_indentation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     134c <sfd_fix_indentation+0x1bc>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <sfd_filesize@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2dfd(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1211 <sfd_fix_indentation+0x81>
movsbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    120c <sfd_fix_indentation+0x7c>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11d5 <sfd_fix_indentation+0x45>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%eax
shl    $0x2,%eax
add    %eax,%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2da1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12d9 <sfd_fix_indentation+0x149>
movsbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    12bc <sfd_fix_indentation+0x12c>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    12d4 <sfd_fix_indentation+0x144>
mov    -0x19(%rbp),%dl
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1231 <sfd_fix_indentation+0xa1>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x10(%rbp),%rdi
lea    0xd01(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1347 <sfd_fix_indentation+0x1b7>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xce2(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1353 <sfd_fix_indentation+0x1c3>
jmp    134c <sfd_fix_indentation+0x1bc>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfd_fix_indentation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     12ac <sfd_fix_indentation+0x11c>
mov    %rax,%r13
mov    %rax,%rdi
call   10b0 <sfd_filesize@plt>
mov    %eax,%ebx
mov    %r13,%rdi
call   1080 <fgetc@plt>
mov    0x2e13(%rip),%r12
xor    %ebp,%ebp
cmp    (%r12),%al
je     11fa <sfd_fix_indentation+0x6a>
xor    %ebp,%ebp
nop
xor    %ecx,%ecx
cmp    $0x9,%al
sete   %cl
add    %ecx,%ebp
mov    %r13,%rdi
call   1080 <fgetc@plt>
cmp    (%r12),%al
jne    11e0 <sfd_fix_indentation+0x50>
shl    $0x2,%ebp
lea    (%rbx,%rbp,1),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1060 <rewind@plt>
mov    %r13,%rdi
call   1080 <fgetc@plt>
xor    %ebp,%ebp
cmp    (%r12),%al
jne    1247 <sfd_fix_indentation+0xb7>
jmp    1263 <sfd_fix_indentation+0xd3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebp,%rbp
mov    %al,(%rbx,%rbp,1)
add    $0x1,%ebp
mov    %r13,%rdi
call   1080 <fgetc@plt>
cmp    (%r12),%al
je     1260 <sfd_fix_indentation+0xd0>
cmp    $0x9,%al
jne    1230 <sfd_fix_indentation+0xa0>
movslq %ebp,%rax
movw   $0x2020,(%rbx,%rax,1)
lea    0x3(%rax),%ebp
movb   $0x20,0x2(%rbx,%rax,1)
mov    $0x20,%al
jmp    1230 <sfd_fix_indentation+0xa0>
movslq %ebp,%rbp
movb   $0x0,(%rbx,%rbp,1)
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1040 <remove@plt>
lea    0xd85(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12ac <sfd_fix_indentation+0x11c>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@EOF = global i8 0
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @sfd_fix_indentation(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %102
14: ; preds = %1
store i32 0, i32* %7
store i32 0, i32* %8
%15 = load i32*, i32** %4
%16 = call i32 @sfd_filesize(i32* %15)
store i32 %16, i32* %9
br label %17
17: ; preds = %31, %14
%18 = load i32*, i32** %4
%19 = call signext i8 @fgetc(i32* %18)
store i8 %19, i8* %5
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 9
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %31
31: ; preds = %28, %24
br label %17
32: ; preds = %17
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = mul nsw i32 %34, 4
%36 = add nsw i32 %33, %35
%37 = add nsw i32 %36, 1
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %6
%39 = load i32*, i32** %4
%40 = call i32 @rewind(i32* %39)
br label %41
41: ; preds = %80, %32
%42 = load i32*, i32** %4
%43 = call signext i8 @fgetc(i32* %42)
store i8 %43, i8* %5
%44 = sext i8 %43 to i32
%45 = load i8, i8* @EOF
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %44, %46
br i1 %47, label %48, label %81
48: ; preds = %41
%49 = load i8, i8* %5
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 9
br i1 %51, label %52, label %73
52: ; preds = %48
%53 = load i8*, i8** %6
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 32, i8* %57
%58 = load i8*, i8** %6
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
store i8 32, i8* %62
%63 = load i8*, i8** %6
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 32, i8* %67
%68 = load i8*, i8** %6
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
%71 = sext i32 %69 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
store i8 32, i8* %72
br label %80
73: ; preds = %48
%74 = load i8, i8* %5
%75 = load i8*, i8** %6
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
%78 = sext i32 %76 to i64
%79 = getelementptr inbounds i8, i8* %75, i64 %78
store i8 %74, i8* %79
br label %80
80: ; preds = %73, %52
br label %41
81: ; preds = %41
%82 = load i8*, i8** %6
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
store i8 0, i8* %85
%86 = load i32*, i32** %4
%87 = call i32 @fclose(i32* %86)
%88 = load i8*, i8** %3
%89 = call i32 @remove(i8* %88)
%90 = load i8*, i8** %3
%91 = call i32* @fopen(i8* %90, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %91, i32** %4
%92 = icmp ne i32* %91, null
br i1 %92, label %93, label %101
93: ; preds = %81
%94 = load i32*, i32** %4
%95 = load i8*, i8** %6
%96 = call i32 @fprintf(i32* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %95)
%97 = load i8*, i8** %6
%98 = call i32 @free(i8* %97)
%99 = load i32*, i32** %4
%100 = call i32 @fclose(i32* %99)
store i32 0, i32* %2
br label %103
101: ; preds = %81
br label %102
102: ; preds = %101, %1
store i32 -1, i32* %2
br label %103
103: ; preds = %102, %93
%104 = load i32, i32* %2
ret i32 %104
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i8 0
@.str.1 = [3 x i8] c"w+\00"
define i32 @sfd_fix_indentation(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %65, label %4
4: ; preds = %1
%5 = tail call i32 @sfd_filesize(i32* %2)
%6 = tail call signext i8 @fgetc(i32* %2)
%7 = load i8, i8* @EOF
%8 = icmp eq i8 %6, %7
br i1 %8, label %20, label %9
9: ; preds = %4, %9
%10 = phi i8 [ %15, %9 ], [ %6, %4 ]
%11 = phi i32 [ %14, %9 ], [ 0, %4 ]
%12 = icmp eq i8 %10, 9
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %11, %13
%15 = tail call signext i8 @fgetc(i32* %2)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %9
18: ; preds = %9
%19 = shl i32 %14, 2
br label %20
20: ; preds = %18, %4
%21 = phi i32 [ 0, %4 ], [ %19, %18 ]
%22 = add i32 %5, 1
%23 = add i32 %22, %21
%24 = tail call i8* @malloc(i32 %23)
%25 = tail call i32 @rewind(i32* %2)
%26 = tail call signext i8 @fgetc(i32* %2)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %54, label %29
29: ; preds = %20, %43
%30 = phi i8 [ %49, %43 ], [ %26, %20 ]
%31 = phi i32 [ %48, %43 ], [ 0, %20 ]
%32 = icmp eq i8 %30, 9
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = add nsw i32 %31, 1
%35 = sext i32 %31 to i64
%36 = getelementptr inbounds i8, i8* %24, i64 %35
store i8 32, i8* %36
%37 = add nsw i32 %31, 2
%38 = sext i32 %34 to i64
%39 = getelementptr inbounds i8, i8* %24, i64 %38
store i8 32, i8* %39
%40 = add nsw i32 %31, 3
%41 = sext i32 %37 to i64
%42 = getelementptr inbounds i8, i8* %24, i64 %41
store i8 32, i8* %42
br label %43
43: ; preds = %29, %33
%44 = phi i32 [ %40, %33 ], [ %31, %29 ]
%45 = phi i8 [ 32, %33 ], [ %30, %29 ]
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %24, i64 %46
store i8 %45, i8* %47
%48 = add nsw i32 %44, 1
%49 = tail call signext i8 @fgetc(i32* %2)
%50 = load i8, i8* @EOF
%51 = icmp eq i8 %49, %50
br i1 %51, label %52, label %29
52: ; preds = %43
%53 = sext i32 %48 to i64
br label %54
54: ; preds = %52, %20
%55 = phi i64 [ 0, %20 ], [ %53, %52 ]
%56 = getelementptr inbounds i8, i8* %24, i64 %55
store i8 0, i8* %56
%57 = tail call i32 @fclose(i32* %2)
%58 = tail call i32 @remove(i8* %0)
%59 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp eq i32* %59, null
br i1 %60, label %65, label %61
61: ; preds = %54
%62 = tail call i32 @fputs(i8* %24, i32* %59)
%63 = tail call i32 @free(i8* %24)
%64 = tail call i32 @fclose(i32* %59)
br label %65
65: ; preds = %1, %54, %61
%66 = phi i32 [ 0, %61 ], [ -1, %54 ], [ -1, %1 ]
ret i32 %66
}