#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*/ msg(char *, char *, int);
char *get_bin_str(unsigned char val) {
  char *str = malloc(9 * sizeof(char));
  if (str == NULL) {
    msg("ERROR: Couldn't allocate new memory. (%s:%d)",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/c-max/ctrl/refs/heads/master/util.c",
        367);
    return NULL;
  }
  int i;
  for (i = 0; i < 8; i++)
    str[i] = (val & (1 << (7 - i))) ? '1' : '0';
  str[8] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<get_bin_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116c <get_bin_str+0x4c>
lea    0xeb2(%rip),%rdi
lea    0xed8(%rip),%rsi
mov    $0x16f,%edx
call   1040 <msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cd <get_bin_str+0xad>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11bd <get_bin_str+0x9d>
movzbl -0x9(%rbp),%edx
mov    $0x7,%ecx
sub    -0x1c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1173 <get_bin_str+0x53>
mov    -0x18(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bin_str>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11f0 <get_bin_str+0xd0>
movzbl %bl,%eax
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeb1(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xeb5(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%eax
mov    %eax,%esi
and    $0x2,%sil
shr    %sil
mov    %eax,%edi
and    $0x4,%dil
shr    $0x2,%dil
mov    %eax,%r8d
and    $0x8,%r8b
shr    $0x3,%r8b
mov    %eax,%r9d
and    $0x10,%r9b
shr    $0x4,%r9b
mov    %eax,%edx
and    $0x20,%dl
shr    $0x5,%dl
mov    %eax,%ecx
and    $0x40,%cl
shr    $0x6,%cl
mov    %eax,%ebx
sar    $0x7,%bl
add    $0x31,%bl
mov    %bl,0x0(%rbp)
xor    $0x31,%cl
mov    %cl,0x1(%rbp)
xor    $0x31,%dl
mov    %dl,0x2(%rbp)
xor    $0x31,%r9b
mov    %r9b,0x3(%rbp)
xor    $0x31,%r8b
mov    %r8b,0x4(%rbp)
xor    $0x31,%dil
mov    %dil,0x5(%rbp)
xor    $0x31,%sil
mov    %sil,0x6(%rbp)
and    $0x1,%al
xor    $0x31,%al
mov    %al,0x7(%rbp)
movb   $0x0,0x8(%rbp)
jmp    1208 <get_bin_str+0xe8>
lea    0xe29(%rip),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x16f,%edx
call   1040 <msg@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"ERROR: Couldn't allocate new memory. (%s:%d)\00"
@.str.1 = [126 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/c-max/ctrl/refs/heads/master/util.c\00"
define i8* @get_bin_str(i8 zeroext %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i32
store i8 %0, i8* %3
%6 = call i8* @malloc(i32 9)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.1, i64 0, i64 0), i32 367)
store i8* null, i8** %2
br label %37
11: ; preds = %1
store i32 0, i32* %5
br label %12
12: ; preds = %30, %11
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 8
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = load i8, i8* %3
%17 = zext i8 %16 to i32
%18 = load i32, i32* %5
%19 = sub nsw i32 7, %18
%20 = shl i32 1, %19
%21 = and i32 %17, %20
%22 = icmp ne i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 49, i32 48
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %15
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %12
33: ; preds = %12
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 8
store i8 0, i8* %35
%36 = load i8*, i8** %4
store i8* %36, i8** %2
br label %37
37: ; preds = %33, %9
%38 = load i8*, i8** %2
ret i8* %38
}

LLVM IR (-O2):
@.str = [45 x i8] c"ERROR: Couldn't allocate new memory. (%s:%d)\00"
@.str.1 = [126 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/c-max/ctrl/refs/heads/master/util.c\00"
define noalias i8* @get_bin_str(i8 zeroext %0) {
%2 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%3 = icmp eq i8* %2, null
br i1 %3, label %34, label %4
4: ; preds = %1
%5 = zext i8 %0 to i32
%6 = insertelement <8 x i32> poison, i32 %5, i64 0
%7 = shufflevector <8 x i32> %6, <8 x i32> poison, <8 x i32> zeroinitializer
%8 = and <8 x i32> %7, <i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128>
%9 = icmp eq <8 x i32> %8, zeroinitializer
%10 = extractelement <8 x i1> %9, i64 7
%11 = select i1 %10, i8 48, i8 49
store i8 %11, i8* %2
%12 = extractelement <8 x i1> %9, i64 6
%13 = select i1 %12, i8 48, i8 49
%14 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %13, i8* %14
%15 = extractelement <8 x i1> %9, i64 5
%16 = select i1 %15, i8 48, i8 49
%17 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %16, i8* %17
%18 = extractelement <8 x i1> %9, i64 4
%19 = select i1 %18, i8 48, i8 49
%20 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %19, i8* %20
%21 = extractelement <8 x i1> %9, i64 3
%22 = select i1 %21, i8 48, i8 49
%23 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %22, i8* %23
%24 = extractelement <8 x i1> %9, i64 2
%25 = select i1 %24, i8 48, i8 49
%26 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %25, i8* %26
%27 = extractelement <8 x i1> %9, i64 1
%28 = select i1 %27, i8 48, i8 49
%29 = getelementptr inbounds i8, i8* %2, i64 6
store i8 %28, i8* %29
%30 = extractelement <8 x i1> %9, i64 0
%31 = select i1 %30, i8 48, i8 49
%32 = getelementptr inbounds i8, i8* %2, i64 7
store i8 %31, i8* %32
%33 = getelementptr inbounds i8, i8* %2, i64 8
store i8 0, i8* %33
br label %36
34: ; preds = %1
%35 = tail call i32 @msg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str.1, i64 0, i64 0), i32 367)
br label %36
36: ; preds = %4, %34
ret i8* %2
}