#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 test3(void) {
  char string[] = "This\tstring\thas\tfive\twords.";
  int count, tabs, tabsize, char_count, print_length;
  printf("\n== test3 =====================================================\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):
<test3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xea9(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x30(%rbp),%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x9,%esi
mov    $0x20,%edx
call   1060 <substitute_char@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x30(%rbp),%esi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movups 0xea7(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xf65(%rip),%rdi
call   1030 <puts@plt>
lea    0xe93(%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    0xe78(%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    0xe5e(%rip),%r13
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xe74(%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    0xe7a(%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    0xe81(%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    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.test3.string = [28 x i8] c"This\09string\09has\09five\09words.\00"
@.str = [65 x i8] c"\0A== test3 =====================================================\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 @test3() {
%1 = alloca [28 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [28 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 [28 x i8], [28 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 [28 x i8], [28 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 [28 x i8], [28 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 [28 x i8], [28 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 [28 x i8], [28 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 [28 x i8], [28 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 [28 x i8], [28 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.test3.string = [28 x i8] c"This\09string\09has\09five\09words.\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== test3 =====================================================\00"
define void @test3() {
%1 = alloca [28 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [28 x i8], [28 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
}