#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 CalculateNumberOfSpaces(int, int);
scalar_t__ my_getline(char *, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ putchar(char);
int main(void) {
  char Buffer[1024];
  int TabSize = 5;
  int i, j, k;
  while (my_getline(Buffer, 1024) > 0) {
    for (i = 0; Buffer[i] != '\0'; i++) {
      if (Buffer[i] == (char)'\t') {
        j = CalculateNumberOfSpaces(i, TabSize);
        printf("param : %d calculated: %d\n", i, j);
        for (k = 0; k < j; k++) {
          putchar((char)' ');
        }
      } else {
        putchar(Buffer[i]);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1060 <my_getline@plt>
cmp    $0x0,%rax
jle    1251 <main+0x111>
movl   $0x0,-0x418(%rbp)
movslq -0x418(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     124c <main+0x10c>
movslq -0x418(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x9,%eax
jne    121f <main+0xdf>
mov    -0x418(%rbp),%edi
mov    -0x414(%rbp),%esi
call   1040 <CalculateNumberOfSpaces@plt>
mov    %eax,-0x41c(%rbp)
mov    -0x418(%rbp),%esi
mov    -0x41c(%rbp),%edx
lea    0xe25(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
cmp    -0x41c(%rbp),%eax
jge    121a <main+0xda>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    11ea <main+0xaa>
jmp    1233 <main+0xf3>
movslq -0x418(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1030 <putchar@plt>
jmp    1238 <main+0xf8>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1181 <main+0x41>
jmp    115c <main+0x1c>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1060 <my_getline@plt>
test   %rax,%rax
jle    11f7 <main+0xb7>
xor    %ebx,%ebx
mov    %rsp,%r14
lea    0xe91(%rip),%r15
jmp    118c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
mov    (%rsp,%rbx,1),%al
test   %al,%al
je     11e0 <main+0xa0>
cmp    $0x9,%al
jne    1180 <main+0x40>
mov    %ebx,%edi
mov    $0x5,%esi
call   1040 <CalculateNumberOfSpaces@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <printf@plt>
test   %ebp,%ebp
jle    1188 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x80>
jmp    1188 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x400,%esi
call   1060 <my_getline@plt>
mov    $0x0,%ebx
test   %rax,%rax
jg     118c <main+0x4c>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"param : %d calculated: %d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i64 @my_getline(i8* %2, i32 1024)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %8, label %28
5: ; preds = %8
%6 = call i64 @my_getline(i8* %2, i32 1024)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %26, label %28
8: ; preds = %0, %26
%9 = phi i64 [ %27, %26 ], [ 0, %0 ]
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
switch i8 %11, label %22 [
i8 0, label %5
i8 9, label %12
]
12: ; preds = %8
%13 = trunc i64 %9 to i32
%14 = call i32 @CalculateNumberOfSpaces(i32 %13, i32 5)
%15 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %24
17: ; preds = %12, %17
%18 = phi i32 [ %20, %17 ], [ 0, %12 ]
%19 = call i32 @putchar(i8 signext 32)
%20 = add nuw nsw i32 %18, 1
%21 = icmp eq i32 %20, %14
br i1 %21, label %24, label %17
22: ; preds = %8
%23 = call i32 @putchar(i8 signext %11)
br label %24
24: ; preds = %17, %12, %22
%25 = add nuw i64 %9, 1
br label %26
26: ; preds = %24, %5
%27 = phi i64 [ %25, %24 ], [ 0, %5 ]
br label %8
28: ; preds = %5, %0
ret i32 0
}