#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char);
const char *logger_make_bitstring(uint32_t val) {
  static char bit_string[1024];
  int i;
  memset(bit_string, 0, 1024);
  for (i = 31; i >= 0; i--) {
    sprintf(bit_string, "%s%c", bit_string, val & (1 << i) ? '1' : '0');
  }
  return bit_string;
}


x86 assembly (clang, -O0):
<logger_make_bitstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f0e(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
movl   $0x1f,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1195 <logger_make_bitstring+0x75>
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0x2ecb(%rip),%rdx
lea    0xe84(%rip),%rsi
mov    %rdx,%rdi
movsbl %al,%ecx
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1145 <logger_make_bitstring+0x25>
lea    0x2ea4(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logger_make_bitstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
lea    0x2f0f(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    $0x1f,%ebp
lea    0xeb4(%rip),%r14
nopl   0x0(%rax)
bt     %ebp,%r15d
mov    $0x31,%ecx
adc    $0xffffffff,%ecx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
add    $0xffffffff,%ebp
jb     1150 <logger_make_bitstring+0x30>
lea    0x2eca(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@logger_make_bitstring.bit_string = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"%s%c\00"
define i8* @logger_make_bitstring(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0), i32 0, i32 1024)
store i32 31, i32* %3
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = shl i32 1, %10
%12 = and i32 %9, %11
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 49, i32 48
%16 = trunc i32 %15 to i8
%17 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0), i8 signext %16)
br label %18
18: ; preds = %8
%19 = load i32, i32* %3
%20 = add nsw i32 %19, -1
store i32 %20, i32* %3
br label %5
21: ; preds = %5
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0)
}

LLVM IR (-O2):
@logger_make_bitstring.bit_string = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"%s%c\00"
define i8* @logger_make_bitstring(i32 %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0), i32 0, i32 1024)
br label %3
3: ; preds = %1, %3
%4 = phi i32 [ 31, %1 ], [ %10, %3 ]
%5 = shl nuw i32 1, %4
%6 = and i32 %5, %0
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8 48, i8 49
%9 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0), i8 signext %8)
%10 = add nsw i32 %4, -1
%11 = icmp eq i32 %4, 0
br i1 %11, label %12, label %3
12: ; preds = %3
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @logger_make_bitstring.bit_string, i64 0, i64 0)
}