#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*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *str_concave(const char *str, char *buffer, int size_limit) {
  int str_size = (int)strlen(str);
  if (str_size <= size_limit) {
    strcpy(buffer, str);
    return buffer;
  }
  int half = (int)size_limit / 2;
  int i = half;
  int left_over = size_limit % 2;
  int apposition_size = 3;
  int end = half - apposition_size + left_over;
  memcpy(buffer, str, half);
  memcpy(buffer + half, "...", apposition_size);
  i += apposition_size;
  memcpy(buffer + i, str + ((str_size - half) + apposition_size - left_over),
         end);
  i += end;
  buffer[i] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<str_concave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1175 <str_concave+0x45>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1222 <str_concave+0xf2>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
movl   $0x3,-0x30(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x30(%rbp),%edx
lea    0xe31(%rip),%rsi
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%eax
sub    -0x24(%rbp),%eax
add    -0x30(%rbp),%eax
sub    -0x2c(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x34(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_concave>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r12
cmp    %r13d,%r12d
jle    11be <str_concave+0x8e>
mov    %r13d,%ebx
shr    $0x1f,%ebx
add    %r13d,%ebx
mov    %ebx,%eax
and    $0xfffffffe,%eax
sub    %eax,%r13d
sar    %ebx
mov    %r13d,%ebp
add    %ebx,%ebp
add    %ebx,%r13d
add    $0xfffffffd,%r13d
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rbx
lea    (%r15,%rbx,1),%rdi
lea    0xe75(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
lea    (%r15,%rbx,1),%rdi
add    $0x3,%rdi
sub    %ebp,%r12d
add    $0x3,%r12d
movslq %r12d,%rsi
add    %r14,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
add    %ebp,%ebx
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
jmp    11c9 <str_concave+0x99>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"...\00"
define i8* @str_concave(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %3
%21 = load i8*, i8** %6
%22 = load i8*, i8** %5
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %6
store i8* %24, i8** %4
br label %73
25: ; preds = %3
%26 = load i32, i32* %7
%27 = sdiv i32 %26, 2
store i32 %27, i32* %9
%28 = load i32, i32* %9
store i32 %28, i32* %10
%29 = load i32, i32* %7
%30 = srem i32 %29, 2
store i32 %30, i32* %11
store i32 3, i32* %12
%31 = load i32, i32* %9
%32 = load i32, i32* %12
%33 = sub nsw i32 %31, %32
%34 = load i32, i32* %11
%35 = add nsw i32 %33, %34
store i32 %35, i32* %13
%36 = load i8*, i8** %6
%37 = load i8*, i8** %5
%38 = load i32, i32* %9
%39 = call i32 @memcpy(i8* %36, i8* %37, i32 %38)
%40 = load i8*, i8** %6
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i32, i32* %12
%45 = call i32 @memcpy(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %12
%47 = load i32, i32* %10
%48 = add nsw i32 %47, %46
store i32 %48, i32* %10
%49 = load i8*, i8** %6
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8*, i8** %5
%54 = load i32, i32* %8
%55 = load i32, i32* %9
%56 = sub nsw i32 %54, %55
%57 = load i32, i32* %12
%58 = add nsw i32 %56, %57
%59 = load i32, i32* %11
%60 = sub nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %53, i64 %61
%63 = load i32, i32* %13
%64 = call i32 @memcpy(i8* %52, i8* %62, i32 %63)
%65 = load i32, i32* %13
%66 = load i32, i32* %10
%67 = add nsw i32 %66, %65
store i32 %67, i32* %10
%68 = load i8*, i8** %6
%69 = load i32, i32* %10
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
store i8 0, i8* %71
%72 = load i8*, i8** %6
store i8* %72, i8** %4
br label %73
73: ; preds = %25, %20
%74 = load i8*, i8** %4
ret i8* %74
}

LLVM IR (-O2):
@.str = [4 x i8] c"...\00"
define i8* @str_concave(i8* %0, i8* returned %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = trunc i64 %4 to i32
%6 = icmp sgt i32 %5, %2
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %29
9: ; preds = %3
%10 = sdiv i32 %2, 2
%11 = srem i32 %2, 2
%12 = add nsw i32 %11, %10
%13 = add nsw i32 %12, -3
%14 = tail call i32 @memcpy(i8* %1, i8* %0, i32 %10)
%15 = sext i32 %10 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = tail call i32 @memcpy(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%18 = add nsw i32 %10, 3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = sub nsw i32 3, %12
%22 = add i32 %21, %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = tail call i32 @memcpy(i8* %20, i8* %24, i32 %13)
%26 = add i32 %12, %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %9, %7
ret i8* %1
}