#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*/ assert(int /*<<< orphan*/);
size_t chars_in_str(char const *, char);
char *expand_tabulation(char const *, size_t, size_t, char *const);
char *malloc(size_t const);
size_t const strlen(char const *);
char *expand_tabulation_a(const char line[], size_t tab_stops) {
  const size_t tab_count = chars_in_str(line, '\t');
  const size_t extra_line_len = tab_count * tab_stops;
  const size_t expanded_line_len = (strlen(line) - tab_count) + extra_line_len;
  char *const expanded_line = malloc(expanded_line_len + 1);
  if (expanded_line != NULL) {
    const char *const end =
        expand_tabulation(line, (size_t)-1, tab_stops, expanded_line);
    assert(*end == '\0' && "The line should be processed till the end");
  }
  return expanded_line;
}


x86 assembly (clang, -O0):
<expand_tabulation_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x9,%esi
call   1070 <chars_in_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
imul   -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11f8 <expand_tabulation_a+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0xffffffffffffffff,%rsi
call   1030 <expand_tabulation@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    11eb <expand_tabulation_a+0x9b>
mov    $0x1,%al
mov    %al,-0x39(%rbp)
jmp    11eb <expand_tabulation_a+0x9b>
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_tabulation_a>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x9,%esi
call   1070 <chars_in_str@plt>
mov    %rax,%r12
mov    %rax,%rbx
imul   %r14,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %r12,%rax
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b5 <expand_tabulation_a+0x65>
mov    %r15,%rdi
mov    $0xffffffffffffffff,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <expand_tabulation@plt>
xor    %edi,%edi
cmpb   $0x0,(%rax)
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [42 x i8] c"The line should be processed till the end\00"
define i8* @expand_tabulation_a(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%10 = load i8*, i8** %3
%11 = call i64 @chars_in_str(i8* %10, i8 signext 9)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = load i64, i64* %4
%14 = mul i64 %12, %13
store i64 %14, i64* %6
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
%17 = load i64, i64* %5
%18 = sub i64 %16, %17
%19 = load i64, i64* %6
%20 = add i64 %18, %19
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = add i64 %21, 1
%23 = call i8* @malloc(i64 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %40
26: ; preds = %2
%27 = load i8*, i8** %3
%28 = load i64, i64* %4
%29 = load i8*, i8** %8
%30 = call i8* @expand_tabulation(i8* %27, i64 -1, i64 %28, i8* %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %26
br label %36
36: ; preds = %35, %26
%37 = phi i1 [ false, %26 ], [ true, %35 ]
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
br label %40
40: ; preds = %36, %2
%41 = load i8*, i8** %8
ret i8* %41
}

LLVM IR (-O2):
define i8* @expand_tabulation_a(i8* %0, i64 %1) {
%3 = tail call i64 @chars_in_str(i8* %0, i8 signext 9)
%4 = mul i64 %3, %1
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = sub i64 1, %3
%7 = add i64 %6, %5
%8 = add i64 %7, %4
%9 = tail call i8* @malloc(i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = tail call i8* @expand_tabulation(i8* %0, i64 -1, i64 %1, i8* %9)
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
br label %17
17: ; preds = %11, %2
ret i8* %9
}