#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 */
char *malloc(int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ strcat(char *, char *);
void getNumberAsBin(int n, char **binBuff) {
  int c, k;
  int typeLength = 32;
  *binBuff = malloc(sizeof(int) << 4);
  for (c = 31; c >= 0; c--) {
    k = n >> c;
    if (k & 1)
      strcat(*binBuff, "1");
    else
      strcat(*binBuff, "0");
  }
  printf("%d(dez) = %s(bin) \n", n, *binBuff);
}


x86 assembly (clang, -O0):
<getNumberAsBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x20,-0x1c(%rbp)
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1f,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11c3 <getNumberAsBin+0x93>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     119d <getNumberAsBin+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <strcat@plt>
jmp    11b0 <getNumberAsBin+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe57(%rip),%rsi
call   1050 <strcat@plt>
jmp    11b5 <getNumberAsBin+0x85>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <getNumberAsBin+0x31>
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNumberAsBin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    $0x40,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x1f,%ebp
lea    0xeab(%rip),%r15
lea    0xea2(%rip),%r12
xchg   %ax,%ax
bt     %ebp,%r14d
mov    (%rbx),%rdi
mov    %r12,%rsi
cmovae %r15,%rsi
call   1050 <strcat@plt>
add    $0xffffffff,%ebp
jb     1160 <getNumberAsBin+0x30>
mov    (%rbx),%rdx
lea    0xe82(%rip),%rdi
mov    %r14d,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [20 x i8] c"%d(dez) = %s(bin) \0A\00"
define void @getNumberAsBin(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 32, i32* %7
%8 = call i8* @malloc(i32 64)
%9 = load i8**, i8*** %4
store i8* %8, i8** %9
store i32 31, i32* %5
br label %10
10: ; preds = %29, %2
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32, i32* %5
%16 = ashr i32 %14, %15
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i8**, i8*** %4
%22 = load i8*, i8** %21
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
24: ; preds = %13
%25 = load i8**, i8*** %4
%26 = load i8*, i8** %25
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %24, %20
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, -1
store i32 %31, i32* %5
br label %10
32: ; preds = %10
%33 = load i32, i32* %3
%34 = load i8**, i8*** %4
%35 = load i8*, i8** %34
%36 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %33, i8* %35)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [20 x i8] c"%d(dez) = %s(bin) \0A\00"
define void @getNumberAsBin(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
store i8* %3, i8** %1
br label %4
4: ; preds = %2, %4
%5 = phi i32 [ 31, %2 ], [ %12, %4 ]
%6 = shl nuw i32 1, %5
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, 0
%9 = load i8*, i8** %1
%10 = select i1 %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%11 = tail call i32 @strcat(i8* %9, i8* %10)
%12 = add nsw i32 %5, -1
%13 = icmp eq i32 %5, 0
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = load i8*, i8** %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %15)
ret void
}