#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 uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void bit_fprint(FILE *stream, uint8_t *bits, int nof_bits) {
  int i;
  fprintf(stream, "[");
  for (i = 0; i < nof_bits - 1; i++) {
    fprintf(stream, "%d,", bits[i]);
  }
  fprintf(stream, "%d]\n", bits[i]);
}


x86 assembly (clang, -O0):
<bit_fprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1178 <bit_fprint+0x68>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <bit_fprint+0x2c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_fprint>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x5b,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
cmp    $0x2,%ebp
jl     116c <bit_fprint+0x4c>
add    $0xffffffff,%ebp
mov    %ebp,%ebp
lea    0xeb2(%rip),%r15
xor    %ebx,%ebx
mov    (%r14,%rbx,4),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <bit_fprint+0x30>
jmp    116e <bit_fprint+0x4e>
xor    %ebp,%ebp
mov    (%r14,%rbp,4),%edx
lea    0xe8b(%rip),%rsi
mov    %r12,%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"[\00"
@.str.1 = [4 x i8] c"%d,\00"
@.str.2 = [5 x i8] c"%d]\0A\00"
define void @bit_fprint(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %10
10: ; preds = %23, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i32*, i32** %4
%17 = load i32*, i32** %5
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %10
26: ; preds = %10
%27 = load i32*, i32** %4
%28 = load i32*, i32** %5
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %32)
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d,\00"
@.str.2 = [5 x i8] c"%d]\0A\00"
define void @bit_fprint(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @fputc(i32 91, i32* %0)
%5 = add i32 %2, -1
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = zext i32 %5 to i64
br label %18
18: ; preds = %3, %16
%19 = phi i64 [ %17, %16 ], [ 0, %3 ]
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %21)
ret void
}