#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*/ calculate_lengths(char *, int, int *, int *);
int count_tabs(char *);
int /*<<< orphan*/ printf(char *, ...);
int substitute_char(char *, char, char);
void test4(void) {
  char string[] = "\t\t\t\t\t\t";
  int count, tabs, tabsize, char_count, print_length;
  printf("\n== test4 =====================================================\n");
  printf("|%s|\n", string);
  tabs = count_tabs(string);
  printf("Number of tabs is %i.\n", tabs);
  tabsize = 4;
  calculate_lengths(string, tabsize, &char_count, &print_length);
  printf("Number of characters in the string is %i.\n", char_count);
  printf("With tab size of %i, the print length is %i.\n", tabsize,
         print_length);
  count = substitute_char(string, '\t', ' ');
  printf("Replacements made: %i. After replacing tabs with spaces:\n", count);
  printf("|%s|\n", string);
  printf("Number of characters in the string is %i.\n", char_count);
  printf("Number of tabs is %i\n", count_tabs(string));
  tabsize = 4;
  calculate_lengths(string, tabsize, &char_count, &print_length);
  printf("Number of characters in the string is %i.\n", char_count);
  printf("With tab size of %i, the print length is %i.\n", tabsize,
         print_length);
}


x86 assembly (clang, -O0):
<test4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xeb2(%rip),%eax
mov    %eax,-0x7(%rbp)
mov    0xeac(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xea4(%rip),%al
mov    %al,-0x1(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7(%rbp),%rsi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x14(%rbp)
lea    -0x7(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x18(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7(%rbp),%rdi
mov    $0x9,%esi
mov    $0x20,%edx
call   1060 <substitute_char@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x7(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x14(%rbp)
lea    -0x7(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x18(%rbp),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x90909,0x13(%rsp)
movl   $0x9090909,0x10(%rsp)
09
lea    0xf58(%rip),%rdi
call   1030 <puts@plt>
lea    0xe86(%rip),%r12
lea    0x10(%rsp),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <count_tabs@plt>
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%r15
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <calculate_lengths@plt>
mov    0x8(%rsp),%esi
lea    0xe51(%rip),%r13
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xe67(%rip),%rbp
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0x20,%edx
call   1070 <substitute_char@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <count_tabs@plt>
lea    0xe74(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <calculate_lengths@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.test4.string = [7 x i8] c"\09\09\09\09\09\09\00"
@.str = [65 x i8] c"\0A== test4 =====================================================\0A\00"
@.str.1 = [6 x i8] c"|%s|\0A\00"
@.str.2 = [23 x i8] c"Number of tabs is %i.\0A\00"
@.str.3 = [43 x i8] c"Number of characters in the string is %i.\0A\00"
@.str.4 = [46 x i8] c"With tab size of %i, the print length is %i.\0A\00"
@.str.5 = [58 x i8] c"Replacements made: %i. After replacing tabs with spaces:\0A\00"
@.str.6 = [22 x i8] c"Number of tabs is %i\0A\00"
define void @test4() {
%1 = alloca [7 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [7 x i8]* %1 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%12 = call i32 @count_tabs(i8* %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i32 4, i32* %4
%15 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @calculate_lengths(i8* %15, i32 %16, i32* %5, i32* %6)
%18 = load i32, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %4
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %20, i32 %21)
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%24 = call i32 @substitute_char(i8* %23, i8 signext 9, i8 signext 32)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%32 = call i32 @count_tabs(i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %32)
store i32 4, i32* %4
%34 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%35 = load i32, i32* %4
%36 = call i32 @calculate_lengths(i8* %34, i32 %35, i32* %5, i32* %6)
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %4
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %39, i32 %40)
ret void
}

LLVM IR (-O2):
@__const.test4.string = [7 x i8] c"\09\09\09\09\09\09\00"
@.str.1 = [6 x i8] c"|%s|\0A\00"
@.str.2 = [23 x i8] c"Number of tabs is %i.\0A\00"
@.str.3 = [43 x i8] c"Number of characters in the string is %i.\0A\00"
@.str.4 = [46 x i8] c"With tab size of %i, the print length is %i.\0A\00"
@.str.5 = [58 x i8] c"Replacements made: %i. After replacing tabs with spaces:\0A\00"
@.str.6 = [22 x i8] c"Number of tabs is %i\0A\00"
@str = [64 x i8] c"\0A== test4 =====================================================\00"
define void @test4() {
%1 = alloca [7 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = call i32 @count_tabs(i8* %4)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = call i32 @calculate_lengths(i8* %4, i32 4, i32* %2, i32* %3)
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 4, i32 %14)
%16 = call i32 @substitute_char(i8* %4, i8 signext 9, i8 signext 32)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = call i32 @count_tabs(i8* %4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = call i32 @calculate_lengths(i8* %4, i32 4, i32* %2, i32* %3)
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 4, i32 %26)
ret void
}