#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
int strlen(char *);
void print_string_size(const char *src, int max, FILE *output) {
  char *s = strdup(src);
  int length = strlen(s);
  if (length >= max) {
    s[max - 1] = '\0';
    s[max - 2] = '.';
    s[max - 3] = '.';
    s[max - 4] = '.';
    length = max;
  }
  fprintf(output, "%s", s);
  length = max - length - 1;
  for (int i = 0; i < length; i++)
    fprintf(output, " ");
  fprintf(output, "\t");
  free(s);
}


x86 assembly (clang, -O0):
<print_string_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11c2 <print_string_size+0x82>
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
sub    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1217 <print_string_size+0xd7>
mov    -0x18(%rbp),%rdi
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11eb <print_string_size+0xab>
mov    -0x18(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
call   1070 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
cmp    %r15d,%eax
jl     1183 <print_string_size+0x33>
movslq %r15d,%rax
movl   $0x2e2e2e,-0x4(%rax,%r14,1)
mov    %r15d,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
not    %ebp
add    %r15d,%ebp
test   %ebp,%ebp
jle    11b2 <print_string_size+0x62>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
add    $0xffffffff,%ebp
jne    11a0 <print_string_size+0x50>
mov    $0x9,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"\09\00"
define void @print_string_size(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = load i32, i32* %5
%16 = icmp sge i32 %14, %15
br i1 %16, label %17, label %39
17: ; preds = %3
%18 = load i8*, i8** %7
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
%23 = load i8*, i8** %7
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 46, i8* %27
%28 = load i8*, i8** %7
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 46, i8* %32
%33 = load i8*, i8** %7
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 46, i8* %37
%38 = load i32, i32* %5
store i32 %38, i32* %8
br label %39
39: ; preds = %17, %3
%40 = load i32*, i32** %6
%41 = load i8*, i8** %7
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = load i32, i32* %5
%44 = load i32, i32* %8
%45 = sub nsw i32 %43, %44
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %8
store i32 0, i32* %9
br label %47
47: ; preds = %54, %39
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = load i32*, i32** %6
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %54
54: ; preds = %51
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %47
57: ; preds = %47
%58 = load i32*, i32** %6
%59 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%60 = load i8*, i8** %7
%61 = call i32 @free(i8* %60)
ret void
}

LLVM IR (-O2):
define void @print_string_size(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i32 @strlen(i8* %4)
%6 = icmp slt i32 %5, %1
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = add nsw i32 %1, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %4, i64 %9
store i8 0, i8* %10
%11 = add nsw i32 %1, -2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 46, i8* %13
%14 = add nsw i32 %1, -3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 46, i8* %16
%17 = add nsw i32 %1, -4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %4, i64 %18
store i8 46, i8* %19
br label %20
20: ; preds = %7, %3
%21 = phi i32 [ %1, %7 ], [ %5, %3 ]
%22 = tail call i32 @fputs(i8* %4, i32* %2)
%23 = xor i32 %21, -1
%24 = add i32 %23, %1
%25 = icmp sgt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %29, %20
%27 = tail call i32 @fputc(i32 9, i32* %2)
%28 = tail call i32 @free(i8* %4)
ret void
29: ; preds = %20, %29
%30 = phi i32 [ %32, %29 ], [ 0, %20 ]
%31 = tail call i32 @fputc(i32 32, i32* %2)
%32 = add nuw nsw i32 %30, 1
%33 = icmp eq i32 %32, %24
br i1 %33, label %26, label %29
}