#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int replace_print(int num, int count, char *buf) {
  int i = 0;
  while (*buf != '\0') {
    switch (*buf) {
    case '\t':
      for (i = 0; i < num - (count % num); i++) {
        fputc(' ', stdout);
      }
      count += num - (count % num);
      break;
    case '\n':
      count = -1;
    default:
      count++;
      fputc(*buf, stdout);
      break;
    }
    buf++;
  }
  return count;
}


x86 assembly (clang, -O0):
<replace_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fc <replace_print+0xec>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
sub    $0x9,%eax
je     1162 <replace_print+0x52>
jmp    1151 <replace_print+0x41>
mov    -0x18(%rbp),%eax
sub    $0xa,%eax
je     11c4 <replace_print+0xb4>
jmp    11cb <replace_print+0xbb>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%eax
cltd
idivl  -0x4(%rbp)
mov    -0x1c(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jge    11a7 <replace_print+0x97>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1030 <fputc@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <replace_print+0x59>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x4(%rbp)
mov    -0x20(%rbp),%eax
sub    %edx,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11eb <replace_print+0xdb>
movl   $0xffffffff,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    0x2dff(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1129 <replace_print+0x19>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    (%rdx),%al
test   %al,%al
je     1198 <replace_print+0x88>
mov    %rdx,%rbx
mov    %edi,%r14d
mov    0x2eaf(%rip),%r12
jmp    115e <replace_print+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xffffffff,%r15d
add    $0x1,%r15d
mov    (%r12),%esi
call   1030 <fputc@plt>
mov    0x1(%rbx),%al
add    $0x1,%rbx
test   %al,%al
je     1198 <replace_print+0x88>
movsbl %al,%edi
cmp    $0xa,%edi
je     1140 <replace_print+0x30>
cmp    $0x9,%edi
jne    1146 <replace_print+0x36>
mov    %r15d,%eax
cltd
idiv   %r14d
mov    %r14d,%r13d
sub    %edx,%r13d
test   %r13d,%r13d
jle    1193 <replace_print+0x83>
mov    %r13d,%ebp
mov    (%r12),%esi
mov    $0x20,%edi
call   1030 <fputc@plt>
add    $0xffffffff,%ebp
jne    1180 <replace_print+0x70>
add    %r13d,%r15d
jmp    1153 <replace_print+0x43>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i32 @replace_print(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
br label %8
8: ; preds = %48, %3
%9 = load i8*, i8** %6
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %51
13: ; preds = %8
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %41 [
i32 9, label %17
i32 10, label %40
]
17: ; preds = %13
store i32 0, i32* %7
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = srem i32 %21, %22
%24 = sub nsw i32 %20, %23
%25 = icmp slt i32 %19, %24
br i1 %25, label %26, label %32
26: ; preds = %18
%27 = load i32, i32* @stdout
%28 = call i32 @fputc(i8 signext 32, i32 %27)
br label %29
29: ; preds = %26
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %18
32: ; preds = %18
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = srem i32 %34, %35
%37 = sub nsw i32 %33, %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, %37
store i32 %39, i32* %5
br label %48
40: ; preds = %13
store i32 -1, i32* %5
br label %41
41: ; preds = %13, %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = load i32, i32* @stdout
%47 = call i32 @fputc(i8 signext %45, i32 %46)
br label %48
48: ; preds = %41, %32
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %6
br label %8
51: ; preds = %8
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @replace_print(i32 %0, i32 %1, i8* nocapture %2) {
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %34, label %6
6: ; preds = %3, %29
%7 = phi i8 [ %32, %29 ], [ %4, %3 ]
%8 = phi i8* [ %31, %29 ], [ %2, %3 ]
%9 = phi i32 [ %30, %29 ], [ %1, %3 ]
%10 = sext i8 %7 to i32
switch i32 %10, label %24 [
i32 9, label %11
i32 10, label %23
]
11: ; preds = %6
%12 = srem i32 %9, %0
%13 = sub i32 %0, %12
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11, %15
%16 = phi i32 [ %19, %15 ], [ 0, %11 ]
%17 = load i32, i32* @stdout
%18 = tail call i32 @fputc(i8 signext 32, i32 %17)
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %19, %13
br i1 %20, label %21, label %15
21: ; preds = %15, %11
%22 = add nsw i32 %13, %9
br label %29
23: ; preds = %6
br label %24
24: ; preds = %6, %23
%25 = phi i32 [ %9, %6 ], [ -1, %23 ]
%26 = add nsw i32 %25, 1
%27 = load i32, i32* @stdout
%28 = tail call i32 @fputc(i8 signext %7, i32 %27)
br label %29
29: ; preds = %24, %21
%30 = phi i32 [ %26, %24 ], [ %22, %21 ]
%31 = getelementptr inbounds i8, i8* %8, i64 1
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %6
34: ; preds = %29, %3
%35 = phi i32 [ %1, %3 ], [ %30, %29 ]
ret i32 %35
}