#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 *NumPBinString(short num) {
  char *ret = calloc(17, sizeof(char));
  unsigned short digitos[16];
  if (ret == NULL)
    parser_Error("Memoria insuficiente para alocacao!");
  unsigned short i = 15;
  for (i = 0; i < 16; i++) {
    digitos[15 - i] = GetBit((unsigned short)num, i);
  }
  for (i = 0; i < 16; i++) {
    ret[i] = (digitos[i] == 1) ? '1' : '0';
  }
  ret[16] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<NumPBinString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    $0x11,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1169 <NumPBinString+0x39>
lea    0xe9c(%rip),%rdi
call   1040 <parser_Error@plt>
movw   $0xf,-0x32(%rbp)
movw   $0x0,-0x32(%rbp)
movzwl -0x32(%rbp),%eax
cmp    $0x10,%eax
jge    11b8 <NumPBinString+0x88>
mov    -0x2(%rbp),%ax
movzwl %ax,%edi
movzwl -0x32(%rbp),%esi
call   1050 <GetBit@plt>
mov    %ax,%cx
movzwl -0x32(%rbp),%edx
mov    $0xf,%eax
sub    %edx,%eax
cltq
mov    %cx,-0x30(%rbp,%rax,2)
mov    -0x32(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x32(%rbp)
jmp    1175 <NumPBinString+0x45>
movw   $0x0,-0x32(%rbp)
movzwl -0x32(%rbp),%eax
cmp    $0x10,%eax
jge    1202 <NumPBinString+0xd2>
movzwl -0x32(%rbp),%eax
movzwl -0x30(%rbp,%rax,2),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movzwl -0x32(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x32(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x32(%rbp)
jmp    11be <NumPBinString+0x8e>
mov    -0x10(%rbp),%rax
movb   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NumPBinString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
mov    $0x11,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,0x30(%rsp)
test   %rax,%rax
jne    1165 <NumPBinString+0x35>
lea    0xec0(%rip),%rdi
call   1040 <parser_Error@plt>
movzwl %bx,%r13d
mov    %r13d,%edi
xor    %esi,%esi
call   1050 <GetBit@plt>
mov    %eax,0x2c(%rsp)
mov    %r13d,%edi
mov    $0x1,%esi
call   1050 <GetBit@plt>
mov    %eax,0x28(%rsp)
mov    %r13d,%edi
mov    $0x2,%esi
call   1050 <GetBit@plt>
mov    %eax,0x24(%rsp)
mov    %r13d,%edi
mov    $0x3,%esi
call   1050 <GetBit@plt>
mov    %eax,0x20(%rsp)
mov    %r13d,%edi
mov    $0x4,%esi
call   1050 <GetBit@plt>
mov    %eax,0x1c(%rsp)
mov    %r13d,%edi
mov    $0x5,%esi
call   1050 <GetBit@plt>
mov    %eax,0x18(%rsp)
mov    %r13d,%edi
mov    $0x6,%esi
call   1050 <GetBit@plt>
mov    %eax,0x14(%rsp)
mov    %r13d,%edi
mov    $0x7,%esi
call   1050 <GetBit@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    $0x8,%esi
call   1050 <GetBit@plt>
mov    %eax,0xc(%rsp)
mov    %r13d,%edi
mov    $0x9,%esi
call   1050 <GetBit@plt>
mov    %eax,0x8(%rsp)
mov    %r13d,%edi
mov    $0xa,%esi
call   1050 <GetBit@plt>
mov    %eax,%r15d
mov    %r13d,%edi
mov    $0xb,%esi
call   1050 <GetBit@plt>
mov    %eax,%r12d
mov    %r13d,%edi
mov    $0xc,%esi
call   1050 <GetBit@plt>
mov    %eax,%ebx
mov    %r13d,%edi
mov    $0xd,%esi
call   1050 <GetBit@plt>
mov    %eax,%ebp
mov    %r13d,%edi
mov    $0xe,%esi
call   1050 <GetBit@plt>
mov    %eax,%r14d
mov    %r13d,%edi
mov    $0xf,%esi
call   1050 <GetBit@plt>
movd   0xc(%rsp),%xmm8
movd   0x8(%rsp),%xmm15
movd   %r15d,%xmm9
movd   %r12d,%xmm2
movd   %ebx,%xmm10
movd   %ebp,%xmm6
movd   %r14d,%xmm11
movd   %eax,%xmm4
movd   0x2c(%rsp),%xmm12
movd   0x28(%rsp),%xmm3
movd   0x24(%rsp),%xmm13
movd   0x20(%rsp),%xmm7
movd   0x1c(%rsp),%xmm14
movd   0x18(%rsp),%xmm5
movd   0x14(%rsp),%xmm0
movd   0x10(%rsp),%xmm1
punpcklwd %xmm8,%xmm15
punpcklwd %xmm9,%xmm2
punpckldq %xmm15,%xmm2
punpcklwd %xmm10,%xmm6
punpcklwd %xmm11,%xmm4
punpckldq %xmm6,%xmm4
punpcklqdq %xmm2,%xmm4
punpcklwd %xmm12,%xmm3
punpcklwd %xmm13,%xmm7
punpckldq %xmm3,%xmm7
punpcklwd %xmm14,%xmm5
punpcklwd %xmm0,%xmm1
punpckldq %xmm5,%xmm1
punpcklqdq %xmm7,%xmm1
movdqa 0xcf0(%rip),%xmm0
pcmpeqw %xmm0,%xmm1
pcmpeqw %xmm0,%xmm4
packsswb %xmm1,%xmm4
movdqa 0xcec(%rip),%xmm0
psubb  %xmm4,%xmm0
mov    0x30(%rsp),%rax
movdqu %xmm0,(%rax)
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [36 x i8] c"Memoria insuficiente para alocacao!\00"
define noalias i8* @NumPBinString(i16 signext %0) {
%2 = tail call dereferenceable_or_null(17) i8* @calloc(i32 17, 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 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 0)
%8 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 1)
%9 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 2)
%10 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 3)
%11 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 4)
%12 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 5)
%13 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 6)
%14 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 7)
%15 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 8)
%16 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 9)
%17 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 10)
%18 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 11)
%19 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 12)
%20 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 13)
%21 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 14)
%22 = tail call zeroext i16 @GetBit(i16 zeroext %0, i16 zeroext 15)
%23 = insertelement <16 x i16> poison, i16 %22, i64 0
%24 = insertelement <16 x i16> %23, i16 %21, i64 1
%25 = insertelement <16 x i16> %24, i16 %20, i64 2
%26 = insertelement <16 x i16> %25, i16 %19, i64 3
%27 = insertelement <16 x i16> %26, i16 %18, i64 4
%28 = insertelement <16 x i16> %27, i16 %17, i64 5
%29 = insertelement <16 x i16> %28, i16 %16, i64 6
%30 = insertelement <16 x i16> %29, i16 %15, i64 7
%31 = insertelement <16 x i16> %30, i16 %14, i64 8
%32 = insertelement <16 x i16> %31, i16 %13, i64 9
%33 = insertelement <16 x i16> %32, i16 %12, i64 10
%34 = insertelement <16 x i16> %33, i16 %11, i64 11
%35 = insertelement <16 x i16> %34, i16 %10, i64 12
%36 = insertelement <16 x i16> %35, i16 %9, i64 13
%37 = insertelement <16 x i16> %36, i16 %8, i64 14
%38 = insertelement <16 x i16> %37, i16 %7, i64 15
%39 = icmp eq <16 x i16> %38, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
%40 = select <16 x i1> %39, <16 x i8> <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>, <16 x i8> <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%41 = bitcast i8* %2 to <16 x i8>*
store <16 x i8> %40, <16 x i8>* %41
ret i8* %2
}