#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*/ batata(char, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  char *texto = "joao doidjo";
  char resultado[strlen(texto) * 8];
  printf("[original] %s\n", texto);
  printf("tamanho do texto original %d\n", (int)strlen(texto));
  for (int i = 0; i < strlen(texto); i++)
    batata(texto[i], resultado, i * 8);
  printf("[resultado] ");
  for (int i = 0; i < strlen(texto) * 8; i++)
    printf("%d", (int)resultado[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
shl    $0x3,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11f2 <main+0xc2>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x24(%rbp),%edx
shl    $0x3,%edx
movsbl %al,%edi
call   1050 <batata@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ab <main+0x7b>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
shl    $0x3,%ecx
cmp    %ecx,%eax
jge    124e <main+0x11e>
mov    -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1207 <main+0xd7>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeae(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
shl    $0x3,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe97(%rip),%rdi
xor    %r12d,%r12d
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11d7 <main+0x97>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%r14,1),%edi
mov    %r15,%rsi
mov    %r12d,%edx
call   1060 <batata@plt>
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    $0x8,%r12d
cmp    %rax,%rbx
jl     11b0 <main+0x70>
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe14(%rip),%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1235 <main+0xf5>
lea    0xe4a(%rip),%r14
lea    0xdfd(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
shl    $0x3,%eax
cltq
cmp    %rax,%rbx
jl     1210 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"joao doidjo\00"
@.str.1 = [15 x i8] c"[original] %s\0A\00"
@.str.2 = [30 x i8] c"tamanho do texto original %d\0A\00"
@.str.3 = [13 x i8] c"[resultado] \00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = mul nsw i32 %8, 8
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %3
%12 = alloca i8, i64 %10
store i64 %10, i64* %4
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %16)
store i32 0, i32* %5
br label %18
18: ; preds = %32, %0
%19 = load i32, i32* %5
%20 = load i8*, i8** %2
%21 = call i32 @strlen(i8* %20)
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %35
23: ; preds = %18
%24 = load i8*, i8** %2
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i32, i32* %5
%30 = mul nsw i32 %29, 8
%31 = call i32 @batata(i8 signext %28, i8* %12, i32 %30)
br label %32
32: ; preds = %23
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %18
35: ; preds = %18
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %37
37: ; preds = %50, %35
%38 = load i32, i32* %6
%39 = load i8*, i8** %2
%40 = call i32 @strlen(i8* %39)
%41 = mul nsw i32 %40, 8
%42 = icmp slt i32 %38, %41
br i1 %42, label %43, label %53
43: ; preds = %37
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %12, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %43
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %37
53: ; preds = %37
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
%55 = load i8*, i8** %3
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@.str = [12 x i8] c"joao doidjo\00"
@.str.1 = [15 x i8] c"[original] %s\0A\00"
@.str.2 = [30 x i8] c"tamanho do texto original %d\0A\00"
@.str.3 = [13 x i8] c"[resultado] \00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = shl nsw i32 %1, 3
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp sgt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %14, %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = icmp sgt i32 %12, 0
br i1 %13, label %27, label %25
14: ; preds = %0, %14
%15 = phi i64 [ %21, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds [12 x i8], [12 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = trunc i64 %15 to i32
%19 = shl i32 %18, 3
%20 = call i32 @batata(i8 signext %17, i8* %4, i32 %19)
%21 = add nuw nsw i64 %15, 1
%22 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %14, label %10
25: ; preds = %27, %10
%26 = call i32 @putchar(i32 10)
ret i32 0
27: ; preds = %10, %27
%28 = phi i64 [ %33, %27 ], [ 0, %10 ]
%29 = getelementptr inbounds i8, i8* %4, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = add nuw nsw i64 %28, 1
%34 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%35 = shl nsw i32 %34, 3
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %33, %36
br i1 %37, label %27, label %25
}