#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(unsigned char *, int);
int strlen(char *);
unsigned char *append_plaintext(unsigned char *plaintext) {
  int plaintext_size, mod, i;
  plaintext_size = strlen((char *)plaintext);
  mod = 8 - (plaintext_size % 8);
  if (mod == 8) {
    return plaintext;
  } else {
    plaintext = (unsigned char *)realloc(plaintext,
                                         (plaintext_size + mod) * sizeof(char));
    if (plaintext == NULL) {
      printf("Sem espaço suficiente\n");
      return NULL;
    }
    for (i = plaintext_size; i < plaintext_size + mod; ++i) {
      plaintext[i] = '*';
    }
    plaintext[i] = '\0';
    plaintext_size = strlen((char *)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    $0x8,%ecx
cltd
idiv   %ecx
mov    $0x8,%eax
sub    %edx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jne    1174 <append_plaintext+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <append_plaintext+0xd4>
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    11b3 <append_plaintext+0x83>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1204 <append_plaintext+0xd4>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    11e4 <append_plaintext+0xb4>
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    11b9 <append_plaintext+0x89>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
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   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0x7(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
sub    %ecx,%eax
je     11ee <append_plaintext+0xae>
mov    %ebx,%r15d
sub    %eax,%r15d
add    $0x8,%r15d
mov    %r14,%rdi
mov    %r15d,%esi
call   1060 <realloc@plt>
test   %rax,%rax
je     11df <append_plaintext+0x9f>
mov    %rax,%r14
movslq %ebx,%rbp
mov    %rax,%rdi
add    %rbp,%rdi
lea    0x1(%rbx),%eax
cmp    %eax,%r15d
cmovg  %r15d,%eax
not    %ebx
add    %eax,%ebx
add    $0x1,%rbx
mov    $0x2a,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
movslq %r15d,%rcx
mov    %rbp,%rax
shl    $0x20,%rax
movabs $0x100000000,%rdx
nopl   (%rax)
add    %rdx,%rax
add    $0x1,%rbp
cmp    %rcx,%rbp
jl     11c0 <append_plaintext+0x80>
sar    $0x20,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
jmp    11ee <append_plaintext+0xae>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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, 8
%11 = sub nsw i32 8, %10
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 8
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %54
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))
store i8* null, i8** %2
br label %54
30: ; preds = %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 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 0, i8* %50
%51 = load i8*, i8** %3
%52 = call i32 @strlen(i8* %51)
store i32 %52, i32* %4
%53 = load i8*, i8** %3
store i8* %53, i8** %2
br label %54
54: ; preds = %46, %28, %14
%55 = load i8*, i8** %2
ret i8* %55
}

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, 8
%4 = icmp eq i32 %3, 0
br i1 %4, label %32, label %5
5: ; preds = %1
%6 = sub nsw i32 8, %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 %21, label %11
11: ; preds = %5
%12 = sext i32 %2 to i64
%13 = getelementptr i8, i8* %9, i64 %12
%14 = add i32 %2, 1
%15 = call i32 @llvm.smax.i32(i32 %7, i32 %14)
%16 = xor i32 %2, -1
%17 = add i32 %15, %16
%18 = zext i32 %17 to i64
%19 = add nuw nsw i64 %18, 1
%20 = sext i32 %7 to i64
br label %23
21: ; preds = %5
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %32
23: ; preds = %11, %23
%24 = phi i64 [ %12, %11 ], [ %25, %23 ]
%25 = add nsw i64 %24, 1
%26 = icmp slt i64 %25, %20
br i1 %26, label %23, label %27
27: ; preds = %23
%28 = shl i64 %25, 32
%29 = ashr exact i64 %28, 32
%30 = getelementptr inbounds i8, i8* %9, i64 %29
store i8 0, i8* %30
%31 = tail call i32 @strlen(i8* %9)
br label %32
32: ; preds = %1, %27, %21
%33 = phi i8* [ null, %21 ], [ %9, %27 ], [ %0, %1 ]
ret i8* %33
}