#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 /*<<< orphan*/ print_spaces(int);
int /*<<< orphan*/ putchar(int);
void detab(int column_start, int tabstop, int character) {
  static int column_count;
  int tab_space;
  if (character == '\t') {
    tab_space = tabstop - column_count % tabstop;
    column_count += tab_space;
    if (column_count < column_start)
      putchar(character);
    else if (column_count - tab_space < column_start)
      print_spaces(tab_space);
    else
      print_spaces(tab_space);
  } else {
    putchar(character);
    ++column_count;
  }
  if (character == '\n')
    column_count = 0;
}


x86 assembly (clang, -O0):
<detab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jne    11af <detab+0x8f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2eed(%rip),%eax
cltd
idivl  -0x8(%rbp)
mov    -0x14(%rbp),%eax
sub    %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    0x2ed8(%rip),%eax
mov    %eax,0x2ed2(%rip)
mov    0x2ecc(%rip),%eax
cmp    -0x4(%rbp),%eax
jge    117e <detab+0x5e>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
jmp    11aa <detab+0x8a>
mov    0x2eb0(%rip),%eax
sub    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119d <detab+0x7d>
mov    -0x10(%rbp),%edi
call   1040 <print_spaces@plt>
jmp    11a5 <detab+0x85>
mov    -0x10(%rbp),%edi
call   1040 <print_spaces@plt>
jmp    11aa <detab+0x8a>
jmp    11c6 <detab+0xa6>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2e77(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e6e(%rip)
cmpl   $0xa,-0xc(%rbp)
jne    11da <detab+0xba>
movl   $0x0,0x2e5a(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detab>:
push   %rbx
cmp    $0x9,%edx
jne    114a <detab+0x2a>
mov    0x2f08(%rip),%ecx
mov    %ecx,%eax
cltd
idiv   %esi
sub    %edx,%esi
add    %esi,%ecx
mov    %ecx,0x2ef9(%rip)
cmp    %edi,%ecx
jge    116c <detab+0x4c>
mov    $0x9,%edi
pop    %rbx
jmp    1030 <putchar@plt>
mov    %edx,%ebx
mov    %edx,%edi
call   1030 <putchar@plt>
mov    0x2edb(%rip),%eax
add    $0x1,%eax
xor    %ecx,%ecx
cmp    $0xa,%ebx
cmovne %eax,%ecx
mov    %ecx,0x2eca(%rip)
pop    %rbx
ret
mov    %esi,%edi
pop    %rbx
jmp    1040 <print_spaces@plt>

LLVM IR (-O0):
@detab.column_count = internal global i32 0
define void @detab(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 9
br i1 %9, label %10, label %39
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* @detab.column_count
%13 = load i32, i32* %5
%14 = srem i32 %12, %13
%15 = sub nsw i32 %11, %14
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = load i32, i32* @detab.column_count
%18 = add nsw i32 %17, %16
store i32 %18, i32* @detab.column_count
%19 = load i32, i32* @detab.column_count
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %10
%23 = load i32, i32* %6
%24 = call i32 @putchar(i32 %23)
br label %38
25: ; preds = %10
%26 = load i32, i32* @detab.column_count
%27 = load i32, i32* %7
%28 = sub nsw i32 %26, %27
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %7
%33 = call i32 @print_spaces(i32 %32)
br label %37
34: ; preds = %25
%35 = load i32, i32* %7
%36 = call i32 @print_spaces(i32 %35)
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %22
br label %44
39: ; preds = %3
%40 = load i32, i32* %6
%41 = call i32 @putchar(i32 %40)
%42 = load i32, i32* @detab.column_count
%43 = add nsw i32 %42, 1
store i32 %43, i32* @detab.column_count
br label %44
44: ; preds = %39, %38
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 0, i32* @detab.column_count
br label %48
48: ; preds = %47, %44
ret void
}

LLVM IR (-O2):
@detab.column_count = internal unnamed_addr global i32 0
define void @detab(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 9
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = load i32, i32* @detab.column_count
%7 = srem i32 %6, %1
%8 = sub nsw i32 %1, %7
%9 = add nsw i32 %8, %6
store i32 %9, i32* @detab.column_count
%10 = icmp slt i32 %9, %0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @putchar(i32 9)
br label %21
13: ; preds = %5
%14 = tail call i32 @print_spaces(i32 %8)
br label %21
15: ; preds = %3
%16 = tail call i32 @putchar(i32 %2)
%17 = load i32, i32* @detab.column_count
%18 = add nsw i32 %17, 1
%19 = icmp eq i32 %2, 10
%20 = select i1 %19, i32 0, i32 %18
store i32 %20, i32* @detab.column_count
br label %21
21: ; preds = %13, %15, %11
ret void
}