#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 atoi(char *);
char *malloc(int);
char *rellena(int /*<<< orphan*/, int);
int strlen(char *);
int /*<<< orphan*/ to_binary(int);
char *get_reg(char *reg) {
  int i = strlen(reg);
  char *num = malloc(i);
  int j = 0;
  while (i > 1) {
    num[j] = reg[j + 1];
    i--;
    j++;
  }
  num[j] = '\0';
  i = atoi(num);
  char *resultado = rellena(to_binary(i), 5);
  return resultado;
}


x86 assembly (clang, -O0):
<get_reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    11b7 <get_reg+0x67>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117b <get_reg+0x2b>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <to_binary@plt>
mov    %eax,%edi
mov    $0x5,%esi
call   1050 <rellena@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_reg>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%ebx
jl     1195 <get_reg+0x35>
add    $0x1,%r15
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <memcpy@plt>
jmp    1197 <get_reg+0x37>
xor    %ebx,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1030 <to_binary@plt>
mov    %eax,%edi
mov    $0x5,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <rellena@plt>

LLVM IR (-O0):
define i8* @get_reg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
store i32 0, i32* %5
br label %11
11: ; preds = %14, %1
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %11
29: ; preds = %11
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %4
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = call i32 @to_binary(i32 %36)
%38 = call i8* @rellena(i32 %37, i32 5)
store i8* %38, i8** %6
%39 = load i8*, i8** %6
ret i8* %39
}

LLVM IR (-O2):
define i8* @get_reg(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i8* @malloc(i32 %2)
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = getelementptr i8, i8* %0, i64 1
%7 = add nsw i32 %2, -1
%8 = zext i32 %7 to i64
%9 = add nsw i32 %2, -1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %5, %1
%12 = phi i64 [ 0, %1 ], [ %10, %5 ]
%13 = getelementptr inbounds i8, i8* %3, i64 %12
store i8 0, i8* %13
%14 = tail call i32 @atoi(i8* %3)
%15 = tail call i32 @to_binary(i32 %14)
%16 = tail call i8* @rellena(i32 %15, i32 5)
ret i8* %16
}