#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 test10(void) {
  char string[] = "Four\nscore\tand\nseven\t"
                  "years\nago\nour fathers\tbrought\n"
                  "forth\ton\nthis\ncontinent a\n"
                  "new\tnation.";
  int count, tabs, tabsize, char_count, print_length;
  printf("\n== test10 ====================================================\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, '\n', ' ');
  printf("Replacements made: %i. After replacing newlines 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));
  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));
}


x86 assembly (clang, -O0):
<test10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x60(%rbp),%rdi
lea    0xe9a(%rip),%rsi
mov    $0x59,%edx
call   1060 <memcpy@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xf11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%esi
lea    0xefa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x4,-0x6c(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x6c(%rbp),%esi
lea    -0x70(%rbp),%rdx
lea    -0x74(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x70(%rbp),%esi
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x6c(%rbp),%esi
mov    -0x74(%rbp),%edx
lea    0xefc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0xa,%esi
mov    $0x20,%edx
call   1070 <substitute_char@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xf03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x70(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,%esi
lea    0xf05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x9,%esi
mov    $0x20,%edx
call   1070 <substitute_char@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xef4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x70(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <count_tabs@plt>
mov    %eax,%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test10>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
movups 0xee7(%rip),%xmm0
movups %xmm0,0x59(%rsp)
movaps 0xed2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe62(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xfb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xea3(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <count_tabs@plt>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <calculate_lengths@plt>
mov    0x8(%rsp),%esi
lea    0xe74(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xe8a(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x20,%edx
call   1070 <substitute_char@plt>
lea    0xe93(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <count_tabs@plt>
lea    0xe9e(%rip),%r12
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0x20,%edx
call   1070 <substitute_char@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <count_tabs@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test10.string = [89 x i8] c"Four\0Ascore\09and\0Aseven\09years\0Aago\0Aour fathers\09brought\0Aforth\09on\0Athis\0Acontinent a\0Anew\09nation.\00"
@.str = [65 x i8] c"\0A== test10 ====================================================\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 = [62 x i8] c"Replacements made: %i. After replacing newlines with spaces:\0A\00"
@.str.6 = [22 x i8] c"Number of tabs is %i\0A\00"
@.str.7 = [58 x i8] c"Replacements made: %i. After replacing tabs with spaces:\0A\00"
define void @test10() {
%1 = alloca [89 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [89 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 [89 x i8], [89 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 [89 x i8], [89 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 [89 x i8], [89 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 [89 x i8], [89 x i8]* %1, i64 0, i64 0
%24 = call i32 @substitute_char(i8* %23, i8 signext 10, i8 signext 32)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [89 x i8], [89 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 [89 x i8], [89 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)
%34 = getelementptr inbounds [89 x i8], [89 x i8]* %1, i64 0, i64 0
%35 = call i32 @substitute_char(i8* %34, i8 signext 9, i8 signext 32)
store i32 %35, i32* %2
%36 = load i32, i32* %2
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [89 x i8], [89 x i8]* %1, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [89 x i8], [89 x i8]* %1, i64 0, i64 0
%43 = call i32 @count_tabs(i8* %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %43)
ret void
}

LLVM IR (-O2):
@__const.test10.string = [89 x i8] c"Four\0Ascore\09and\0Aseven\09years\0Aago\0Aour fathers\09brought\0Aforth\09on\0Athis\0Acontinent a\0Anew\09nation.\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 = [62 x i8] c"Replacements made: %i. After replacing newlines with spaces:\0A\00"
@.str.6 = [22 x i8] c"Number of tabs is %i\0A\00"
@.str.7 = [58 x i8] c"Replacements made: %i. After replacing tabs with spaces:\0A\00"
@str = [64 x i8] c"\0A== test10 ====================================================\00"
define void @test10() {
%1 = alloca [89 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [89 x i8], [89 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 10, i8 signext 32)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 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 @substitute_char(i8* %4, i8 signext 9, i8 signext 32)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call i32 @count_tabs(i8* %4)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %28)
ret void
}