#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 atoi(char *);
int getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
main(int argc, char *argv[]) {
  int c, n, i;
  int cur;
  if (argc == 1)
    n = 8;
  else if (argc == 2)
    n = atoi(*++argv);
  else {
    printf("Usage: detab (8)(tab stop)\n");
    return 1;
  }
  cur = 0;
  while ((c = getchar()) != EOF) {
    if (c == '\t') {
      for (i = n - cur; i > 0; --i)
        putchar(' ');
      cur = 0;
    } else {
      putchar(c);
      ++cur;
      if (cur >= n || c == '\n')
        cur = 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    116c <main+0x2c>
movl   $0x8,-0x18(%rbp)
jmp    11b3 <main+0x73>
cmpl   $0x2,-0x8(%rbp)
jne    1196 <main+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    11ae <main+0x6e>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124c <main+0x10c>
jmp    11b3 <main+0x73>
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%eax
je     124c <main+0x10c>
cmpl   $0x9,-0x14(%rbp)
jne    1214 <main+0xd4>
mov    -0x18(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1208 <main+0xc8>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e6 <main+0xa6>
movl   $0x0,-0x20(%rbp)
jmp    1247 <main+0x107>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    123b <main+0xfb>
cmpl   $0xa,-0x14(%rbp)
jne    1242 <main+0x102>
movl   $0x0,-0x20(%rbp)
jmp    1247 <main+0x107>
jmp    11ba <main+0x7a>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
je     1167 <main+0x27>
cmp    $0x2,%edi
jne    1204 <main+0xc4>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
jmp    116d <main+0x2d>
mov    $0x8,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
mov    0x2e69(%rip),%rax
cmp    (%rax),%ebp
je     1215 <main+0xd5>
lea    0x1(%r14),%eax
mov    %eax,0x4(%rsp)
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    11d5 <main+0x95>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1030 <putchar@plt>
add    $0x1,%r12d
cmp    $0xa,%ebp
mov    %r12d,%r15d
cmove  %r13d,%r15d
cmp    %r14d,%r12d
cmovge %r13d,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
mov    %r15d,%r12d
mov    0x2e17(%rip),%rax
cmp    (%rax),%ebp
je     1215 <main+0xd5>
cmp    $0x9,%ebp
jne    11a0 <main+0x60>
xor    %r15d,%r15d
cmp    %r12d,%r14d
jle    11bc <main+0x7c>
mov    0x4(%rsp),%ebx
sub    %r12d,%ebx
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     11f0 <main+0xb0>
jmp    11bc <main+0x7c>
lea    0xdf5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@str = [27 x i8] c"Usage: detab (8)(tab stop)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %7 [
i32 1, label %9
i32 2, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32 @atoi(i8* %5)
br label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %38
9: ; preds = %2, %3
%10 = phi i32 [ %6, %3 ], [ 8, %2 ]
%11 = tail call i32 (...) @getchar()
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %38, label %14
14: ; preds = %9, %33
%15 = phi i32 [ %35, %33 ], [ %11, %9 ]
%16 = phi i32 [ %34, %33 ], [ 0, %9 ]
%17 = icmp eq i32 %15, 9
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = sub nsw i32 %10, %16
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %18, %21
%22 = phi i32 [ %24, %21 ], [ %19, %18 ]
%23 = tail call i32 @putchar(i32 32)
%24 = add nsw i32 %22, -1
%25 = icmp ugt i32 %22, 1
br i1 %25, label %21, label %33
26: ; preds = %14
%27 = tail call i32 @putchar(i32 %15)
%28 = add nsw i32 %16, 1
%29 = icmp sge i32 %28, %10
%30 = icmp eq i32 %15, 10
%31 = or i1 %29, %30
%32 = select i1 %31, i32 0, i32 %28
br label %33
33: ; preds = %21, %18, %26
%34 = phi i32 [ %32, %26 ], [ 0, %18 ], [ 0, %21 ]
%35 = tail call i32 (...) @getchar()
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %14
38: ; preds = %33, %9, %7
%39 = phi i32 [ 1, %7 ], [ 0, %9 ], [ 0, %33 ]
ret i32 %39
}