#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 */

/* Variables and functions */
int EOF;
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int detab(void) {
  int i, j, c;
  char line[1000];
  for (i = 0; i < 1000 - 1 && (c = getchar()) != EOF && c != '\n'; ++i) {
    if (c == '\t') {
      j = 4 - (i % 4);
      while (j-- != 0) {
        line[i] = ' ';
        ++i;
      }
      --i;
    } else {
      line[i] = c;
    }
  }
  line[i] = '\0';
  printf("%s\n", line);
  return i;
}


x86 assembly (clang, -O0):
<detab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x3e7,-0x4(%rbp)
mov    %al,-0x401(%rbp)
jge    1177 <detab+0x57>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e8c(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x401(%rbp)
je     1177 <detab+0x57>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0x401(%rbp)
mov    -0x401(%rbp),%al
test   $0x1,%al
jne    118a <detab+0x6a>
jmp    1208 <detab+0xe8>
cmpl   $0x9,-0xc(%rbp)
jne    11e5 <detab+0xc5>
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    $0x4,%eax
sub    %edx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11d7 <detab+0xb7>
movslq -0x4(%rbp),%rax
movb   $0x20,-0x400(%rbp,%rax,1)
20
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <detab+0x89>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <detab+0xd5>
mov    -0xc(%rbp),%eax
mov    %al,%cl
movslq -0x4(%rbp),%rax
mov    %cl,-0x400(%rbp,%rax,1)
jmp    11fa <detab+0xda>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1132 <detab+0x12>
movslq -0x4(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detab>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    0x2ea6(%rip),%r14
xor    %ebx,%ebx
jmp    1163 <detab+0x33>
cs nopw 0x0(%rax,%rax,1)
movslq %ebx,%rcx
mov    %al,(%rsp,%rcx,1)
lea    0x1(%rbx),%eax
cmp    $0x3e6,%ebx
mov    %eax,%ebx
jge    11a5 <detab+0x75>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11a3 <detab+0x73>
cmp    (%r14),%eax
je     11a3 <detab+0x73>
cmp    $0x9,%eax
jne    1150 <detab+0x20>
lea    0x3(%rbx),%ebp
test   %ebx,%ebx
cmovns %ebx,%ebp
and    $0xfffffffc,%ebp
mov    %ebp,%edx
sub    %ebx,%edx
add    $0x4,%edx
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
mov    $0x20,%esi
call   1040 <memset@plt>
or     $0x3,%ebp
mov    %ebp,%ebx
jmp    1156 <detab+0x26>
mov    %ebx,%eax
movslq %eax,%rbx
movb   $0x0,(%rsp,%rbx,1)
lea    0xe4d(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @detab() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
store i32 0, i32* %1
br label %5
5: ; preds = %44, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 999
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = call i32 (...) @getchar()
store i32 %9, i32* %3
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 10
br label %15
15: ; preds = %12, %8, %5
%16 = phi i1 [ false, %8 ], [ false, %5 ], [ %14, %12 ]
br i1 %16, label %17, label %47
17: ; preds = %15
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 9
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i32, i32* %1
%22 = srem i32 %21, 4
%23 = sub nsw i32 4, %22
store i32 %23, i32* %2
br label %24
24: ; preds = %28, %20
%25 = load i32, i32* %2
%26 = add nsw i32 %25, -1
store i32 %26, i32* %2
%27 = icmp ne i32 %25, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %30
store i8 32, i8* %31
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
br label %24
34: ; preds = %24
%35 = load i32, i32* %1
%36 = add nsw i32 %35, -1
store i32 %36, i32* %1
br label %43
37: ; preds = %17
%38 = load i32, i32* %3
%39 = trunc i32 %38 to i8
%40 = load i32, i32* %1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %41
store i8 %39, i8* %42
br label %43
43: ; preds = %37, %34
br label %44
44: ; preds = %43
%45 = load i32, i32* %1
%46 = add nsw i32 %45, 1
store i32 %46, i32* %1
br label %5
47: ; preds = %15
%48 = load i32, i32* %1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %49
store i8 0, i8* %50
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @detab() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %24
%4 = phi i32 [ 0, %0 ], [ %26, %24 ]
%5 = tail call i32 (...) @getchar()
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
%8 = icmp ne i32 %5, 10
%9 = and i1 %8, %7
br i1 %9, label %10, label %28
10: ; preds = %3
%11 = icmp eq i32 %5, 9
br i1 %11, label %12, label %20
12: ; preds = %10
%13 = srem i32 %4, 4
%14 = sub nsw i32 4, %13
%15 = sext i32 %4 to i64
%16 = getelementptr [1000 x i8], [1000 x i8]* %1, i64 0, i64 %15
%17 = zext i32 %14 to i64
%18 = sub i32 %4, %13
%19 = add i32 %18, 3
br label %24
20: ; preds = %10
%21 = trunc i32 %5 to i8
%22 = sext i32 %4 to i64
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %22
store i8 %21, i8* %23
br label %24
24: ; preds = %12, %20
%25 = phi i32 [ %19, %12 ], [ %4, %20 ]
%26 = add nsw i32 %25, 1
%27 = icmp slt i32 %25, 998
br i1 %27, label %3, label %28
28: ; preds = %24, %3
%29 = phi i32 [ %26, %24 ], [ %4, %3 ]
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 %29
}