#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 */
unsigned short GetBit(unsigned short, unsigned short);
char *calloc(int, int);
int /*<<< orphan*/ parser_Error(char *);
char *NumPBinString4(short num) {
  char *ret = calloc(5, sizeof(char));
  unsigned short digitos[4];
  if (ret == NULL)
    parser_Error("Memoria insuficiente para alocacao!");
  unsigned short i = 3;
  if (num > 15)
    parser_Error("Shift Rx, N com N maior que 15!");
  for (i = 0; i < 4; i++) {
    digitos[3 - i] = GetBit((unsigned short)num, i);
  }
  for (i = 0; i < 4; i++) {
    ret[i] = (digitos[i] == 1) ? '1' : '0';
  }
  ret[4] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<NumPBinString4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    $0x5,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1169 <NumPBinString4+0x39>
lea    0xe9c(%rip),%rdi
call   1040 <parser_Error@plt>
movw   $0x3,-0x1a(%rbp)
movswl -0x2(%rbp),%eax
cmp    $0xf,%eax
jle    1188 <NumPBinString4+0x58>
lea    0xea1(%rip),%rdi
call   1040 <parser_Error@plt>
movw   $0x0,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
cmp    $0x4,%eax
jge    11d1 <NumPBinString4+0xa1>
mov    -0x2(%rbp),%ax
movzwl %ax,%edi
movzwl -0x1a(%rbp),%esi
call   1050 <GetBit@plt>
mov    %ax,%cx
movzwl -0x1a(%rbp),%edx
mov    $0x3,%eax
sub    %edx,%eax
cltq
mov    %cx,-0x18(%rbp,%rax,2)
mov    -0x1a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
jmp    118e <NumPBinString4+0x5e>
movw   $0x0,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
cmp    $0x4,%eax
jge    121b <NumPBinString4+0xeb>
movzwl -0x1a(%rbp),%eax
movzwl -0x18(%rbp,%rax,2),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
jmp    11d7 <NumPBinString4+0xa7>
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NumPBinString4>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebp
mov    $0x5,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11de <NumPBinString4+0xae>
cmp    $0x10,%bp
jl     1167 <NumPBinString4+0x37>
lea    0xec2(%rip),%rdi
call   1040 <parser_Error@plt>
movzwl %bp,%ebp
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <GetBit@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <GetBit@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    $0x2,%esi
call   1050 <GetBit@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    $0x3,%esi
call   1050 <GetBit@plt>
cmp    $0x1,%ax
sete   %al
or     $0x30,%al
mov    %al,(%rbx)
cmp    $0x1,%r12w
sete   %al
or     $0x30,%al
mov    %al,0x1(%rbx)
cmp    $0x1,%r15w
sete   %al
or     $0x30,%al
mov    %al,0x2(%rbx)
cmp    $0x1,%r14w
sete   %al
or     $0x30,%al
mov    %al,0x3(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1b(%rip),%rdi
call   1040 <parser_Error@plt>
cmp    $0x10,%bp
jge    115b <NumPBinString4+0x2b>
jmp    1167 <NumPBinString4+0x37>

LLVM IR (-O0):
@.str = [36 x i8] c"Memoria insuficiente para alocacao!\00"
@.str.1 = [32 x i8] c"Shift Rx, N com N maior que 15!\00"
define i8* @NumPBinString4(i16 signext %0) {
%2 = alloca i16
%3 = alloca i8*
%4 = alloca [4 x i16]
%5 = alloca i16
store i16 %0, i16* %2
%6 = call i8* @calloc(i32 5, i32 1)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @parser_Error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
store i16 3, i16* %5
%12 = load i16, i16* %2
%13 = sext i16 %12 to i32
%14 = icmp sgt i32 %13, 15
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @parser_Error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
store i16 0, i16* %5
br label %18
18: ; preds = %31, %17
%19 = load i16, i16* %5
%20 = zext i16 %19 to i32
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i16, i16* %2
%24 = load i16, i16* %5
%25 = call zeroext i16 @GetBit(i16 zeroext %23, i16 zeroext %24)
%26 = load i16, i16* %5
%27 = zext i16 %26 to i32
%28 = sub nsw i32 3, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 %29
store i16 %25, i16* %30
br label %31
31: ; preds = %22
%32 = load i16, i16* %5
%33 = add i16 %32, 1
store i16 %33, i16* %5
br label %18
34: ; preds = %18
store i16 0, i16* %5
br label %35
35: ; preds = %53, %34
%36 = load i16, i16* %5
%37 = zext i16 %36 to i32
%38 = icmp slt i32 %37, 4
br i1 %38, label %39, label %56
39: ; preds = %35
%40 = load i16, i16* %5
%41 = zext i16 %40 to i64
%42 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 %41
%43 = load i16, i16* %42
%44 = zext i16 %43 to i32
%45 = icmp eq i32 %44, 1
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 49, i32 48
%48 = trunc i32 %47 to i8
%49 = load i8*, i8** %3
%50 = load i16, i16* %5
%51 = zext i16 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 %48, i8* %52
br label %53
53: ; preds = %39
%54 = load i16, i16* %5
%55 = add i16 %54, 1
store i16 %55, i16* %5
br label %35
56: ; preds = %35
%57 = load i8*, i8** %3
%58 = getelementptr inbounds i8, i8* %57, i64 4
store i8 0, i8* %58
%59 = load i8*, i8** %3
ret i8* %59
}

LLVM IR (-O2):
@.str = [36 x i8] c"Memoria insuficiente para alocacao!\00"
@.str.1 = [32 x i8] c"Shift Rx, N com N maior que 15!\00"
define noalias i8* @NumPBinString4(i16 signext %0) {
%2 = tail call dereferenceable_or_null(5) i8* @calloc(i32 5, i32 1)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @parser_Error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = icmp sgt i16 %0, 15
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @parser_Error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 0)
%12 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 1)
%13 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 2)
%14 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 3)
%15 = icmp eq i16 %14, 1
%16 = select i1 %15, i8 49, i8 48
store i8 %16, i8* %2
%17 = icmp eq i16 %13, 1
%18 = select i1 %17, i8 49, i8 48
%19 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %18, i8* %19
%20 = icmp eq i16 %12, 1
%21 = select i1 %20, i8 49, i8 48
%22 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %21, i8* %22
%23 = icmp eq i16 %11, 1
%24 = select i1 %23, i8 49, i8 48
%25 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %24, i8* %25
ret i8* %2
}