#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*/ printf(char *);
scalar_t__ realloc(char *, int);
int strlen(char *);
char *append_plaintext(char *plaintext) {
  int plaintext_size, mod, i;
  plaintext_size = strlen(plaintext);
  mod = 16 - (plaintext_size % 16);
  if (mod == 16) {
    return plaintext;
  } else {
    plaintext =
        (char *)realloc(plaintext, (plaintext_size + mod) * sizeof(char));
    if (plaintext == NULL) {
      printf("Sem espaço suficiente\n");
    }
    for (i = plaintext_size; i < plaintext_size + mod; ++i) {
      plaintext[i] = '*';
    }
    plaintext_size = strlen(plaintext);
    return plaintext;
  }
}


x86 assembly (clang, -O0):
<append_plaintext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    $0x10,%eax
sub    %edx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jne    1174 <append_plaintext+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11eb <append_plaintext+0xbb>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <append_plaintext+0x76>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    11d7 <append_plaintext+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2a,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ac <append_plaintext+0x7c>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_plaintext>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xf(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff0,%ecx
sub    %ecx,%eax
je     11b0 <append_plaintext+0x70>
mov    %ebx,%ebp
sub    %eax,%ebp
add    $0x10,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1182 <append_plaintext+0x42>
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
movslq %ebx,%rax
mov    %r14,%rdi
add    %rax,%rdi
lea    0x1(%rbx),%eax
cmp    %eax,%ebp
cmovg  %ebp,%eax
not    %ebx
add    %eax,%ebx
add    $0x1,%rbx
mov    $0x2a,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Sem espa\C3\A7o suficiente\0A\00"
define i8* @append_plaintext(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = srem i32 %9, 16
%11 = sub nsw i32 16, %10
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 16
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %50
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i64 @realloc(i8* %17, i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
%31 = load i32, i32* %4
store i32 %31, i32* %6
br label %32
32: ; preds = %43, %30
%33 = load i32, i32* %6
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = add nsw i32 %34, %35
%37 = icmp slt i32 %33, %36
br i1 %37, label %38, label %46
38: ; preds = %32
%39 = load i8*, i8** %3
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 42, i8* %42
br label %43
43: ; preds = %38
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %32
46: ; preds = %32
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* %47)
store i32 %48, i32* %4
%49 = load i8*, i8** %3
store i8* %49, i8** %2
br label %50
50: ; preds = %46, %14
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
@str = [23 x i8] c"Sem espa\C3\A7o suficiente\00"
define i8* @append_plaintext(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = srem i32 %2, 16
%4 = icmp eq i32 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = sub nsw i32 16, %3
%7 = add nsw i32 %6, %2
%8 = tail call i64 @realloc(i8* %0, i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %11, %5
%14 = sext i32 %2 to i64
%15 = getelementptr i8, i8* %9, i64 %14
%16 = add i32 %2, 1
%17 = call i32 @llvm.smax.i32(i32 %7, i32 %16)
%18 = xor i32 %2, -1
%19 = add i32 %17, %18
%20 = zext i32 %19 to i64
%21 = add nuw nsw i64 %20, 1
%22 = tail call i32 @strlen(i8* %9)
br label %23
23: ; preds = %1, %13
%24 = phi i8* [ %9, %13 ], [ %0, %1 ]
ret i8* %24
}