#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*/ printf(char *, int, int);
int convertBlankString(char string[], int index, int charbuffer) {
  int tabsNeeded = 0;
  int blanksNeeded = 0;
  int j;
  extern int numBlanks;
  tabsNeeded = numBlanks / 4;
  blanksNeeded = numBlanks % 4;
  index = index - numBlanks;
  numBlanks = 0;
  printf("We will need %d TABS and %d BLANKS\n", tabsNeeded, blanksNeeded);
  for (j = 0; j < tabsNeeded; ++j) {
    string[index] = '\t';
    ++index;
  }
  for (j = 0; j < blanksNeeded; ++j) {
    string[index] = ' ';
    ++index;
  }
  string[index] = charbuffer;
  return index;
}


x86 assembly (clang, -O0):
<convertBlankString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e7e(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e72(%rip),%rax
movl   $0x0,(%rax)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bc <convertBlankString+0xac>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x9,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <convertBlankString+0x7d>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f2 <convertBlankString+0xe2>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c3 <convertBlankString+0xb3>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertBlankString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2ea6(%rip),%rax
mov    (%rax),%ebx
lea    0x3(%rbx),%ecx
test   %ebx,%ebx
cmovns %ebx,%ecx
mov    %ecx,%r13d
sar    $0x2,%r13d
and    $0xfffffffc,%ecx
mov    %ebx,%r12d
sub    %ecx,%r12d
sub    %ebx,%ebp
movl   $0x0,(%rax)
lea    0xe9d(%rip),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1030 <printf@plt>
cmp    $0x4,%ebx
jl     118f <convertBlankString+0x6f>
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rdi
lea    -0x1(%r13),%edx
add    $0x1,%rdx
mov    $0x9,%esi
call   1040 <memset@plt>
add    %r13d,%ebp
test   %r12d,%r12d
jle    11ab <convertBlankString+0x8b>
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rdi
mov    %r12d,%edx
mov    $0x20,%esi
call   1040 <memset@plt>
add    %r12d,%ebp
movslq %ebp,%rax
mov    %r14b,(%r15,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@numBlanks = external global i32
@.str = [36 x i8] c"We will need %d TABS and %d BLANKS\0A\00"
define i32 @convertBlankString(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = load i32, i32* @numBlanks
%5 = sdiv i32 %4, 4
%6 = srem i32 %4, 4
%7 = sub i32 %1, %4
store i32 0, i32* @numBlanks
%8 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%9 = icmp sgt i32 %4, 3
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = sext i32 %7 to i64
%12 = getelementptr i8, i8* %0, i64 %11
%13 = add nsw i32 %5, -1
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 1
%16 = add i32 %7, %5
br label %17
17: ; preds = %10, %3
%18 = phi i32 [ %7, %3 ], [ %16, %10 ]
%19 = icmp sgt i32 %6, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = sext i32 %18 to i64
%22 = getelementptr i8, i8* %0, i64 %21
%23 = zext i32 %6 to i64
%24 = add i32 %18, %6
br label %25
25: ; preds = %20, %17
%26 = phi i32 [ %18, %17 ], [ %24, %20 ]
%27 = trunc i32 %2 to i8
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 %27, i8* %29
ret i32 %26
}