#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 /*<<< orphan*/ printf(char *, ...);
void test2(void) {
  char string[] = "This\tstring\thas\tfive\twords.";
  int char_count, print_length, tabsize = 2;
  calculate_lengths(string, tabsize, &char_count, &print_length);
  printf("\n== test2 =====================================================\n");
  printf("|%s|\n", string);
  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);
  tabsize = 3;
  calculate_lengths(string, tabsize, &char_count, &print_length);
  printf("With tab size of %i, the print length is %i.\n", tabsize,
         print_length);
  tabsize = 6;
  calculate_lengths(string, tabsize, &char_count, &print_length);
  printf("With tab size of %i, the print length is %i.\n", tabsize,
         print_length);
  tabsize = 8;
  calculate_lengths(string, tabsize, &char_count, &print_length);
  printf("With tab size of %i, the print length is %i.\n", tabsize,
         print_length);
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xec9(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x2,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <calculate_lengths@plt>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x3,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x6,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x8,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <calculate_lengths@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
movups 0xeca(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xeb2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
mov    %r12,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <calculate_lengths@plt>
lea    0xeff(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edx
lea    0xe9e(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x3,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <calculate_lengths@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x6,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <calculate_lengths@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x8,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <calculate_lengths@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test2.string = [28 x i8] c"This\09string\09has\09five\09words.\00"
@.str = [65 x i8] c"\0A== test2 =====================================================\0A\00"
@.str.1 = [6 x i8] c"|%s|\0A\00"
@.str.2 = [43 x i8] c"Number of characters in the string is %i.\0A\00"
@.str.3 = [46 x i8] c"With tab size of %i, the print length is %i.\0A\00"
define void @test2() {
%1 = alloca [28 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast [28 x i8]* %1 to i8*
store i32 2, i32* %4
%6 = getelementptr inbounds [28 x i8], [28 x i8]* %1, i64 0, i64 0
%7 = load i32, i32* %4
%8 = call i32 @calculate_lengths(i8* %6, i32 %7, i32* %2, i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [28 x i8], [28 x i8]* %1, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %15)
store i32 3, i32* %4
%17 = getelementptr inbounds [28 x i8], [28 x i8]* %1, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @calculate_lengths(i8* %17, i32 %18, i32* %2, i32* %3)
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %21)
store i32 6, i32* %4
%23 = getelementptr inbounds [28 x i8], [28 x i8]* %1, i64 0, i64 0
%24 = load i32, i32* %4
%25 = call i32 @calculate_lengths(i8* %23, i32 %24, i32* %2, i32* %3)
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27)
store i32 8, i32* %4
%29 = getelementptr inbounds [28 x i8], [28 x i8]* %1, i64 0, i64 0
%30 = load i32, i32* %4
%31 = call i32 @calculate_lengths(i8* %29, i32 %30, i32* %2, i32* %3)
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
ret void
}

LLVM IR (-O2):
@__const.test2.string = [28 x i8] c"This\09string\09has\09five\09words.\00"
@.str.1 = [6 x i8] c"|%s|\0A\00"
@.str.2 = [43 x i8] c"Number of characters in the string is %i.\0A\00"
@.str.3 = [46 x i8] c"With tab size of %i, the print length is %i.\0A\00"
@str = [64 x i8] c"\0A== test2 =====================================================\00"
define void @test2() {
%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 = call i32 @calculate_lengths(i8* %4, i32 2, i32* %2, i32* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 2, i32 %12)
%14 = call i32 @calculate_lengths(i8* %4, i32 3, i32* %2, i32* %3)
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 3, i32 %15)
%17 = call i32 @calculate_lengths(i8* %4, i32 6, i32* %2, i32* %3)
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 6, i32 %18)
%20 = call i32 @calculate_lengths(i8* %4, i32 8, i32* %2, i32* %3)
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 8, i32 %21)
ret void
}