#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 */
int /*<<< orphan*/ snprintf(char *, int, char *, long);
scalar_t__ strlen(char *);
void stub1(int);
void stub2(int);
void stub3(int);
void bc_out_long(long val, int size, int space, void (*out_char)(int)) {
  char digits[40];
  int len, ix;
  if (space)
    (*out_char)(' ');
  snprintf(digits, 39, "%ld", val);
  len = (int)strlen(digits);
  while (size > len) {
    (*out_char)('0');
    size--;
  }
  for (ix = 0; ix < len; ix++)
    (*out_char)(digits[ix]);
}


x86 assembly (clang, -O0):
<bc_out_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1148 <bc_out_long+0x28>
mov    $0x20,%edi
call   *-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x27,%esi
lea    0xea4(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x44(%rbp),%eax
jle    118f <bc_out_long+0x6f>
mov    $0x30,%edi
call   *-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    116d <bc_out_long+0x4d>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11bf <bc_out_long+0x9f>
mov    -0x18(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsbl -0x40(%rbp,%rcx,1),%edi
call   *%rax
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1196 <bc_out_long+0x76>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bc_out_long>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r12
mov    %esi,%ebp
mov    %rdi,%r14
test   %edx,%edx
je     1140 <bc_out_long+0x20>
mov    $0x20,%edi
call   *%r12
lea    0xeb9(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x27,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
cmp    %ebp,%r14d
jge    1180 <bc_out_long+0x60>
nopw   0x0(%rax,%rax,1)
mov    $0x30,%edi
call   *%r12
add    $0xffffffff,%ebp
cmp    %r14d,%ebp
jg     1170 <bc_out_long+0x50>
test   %r14d,%r14d
jle    11a0 <bc_out_long+0x80>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%rsp,%rbx,1),%edi
call   *%r12
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <bc_out_long+0x70>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
define void @bc_out_long(i64 %0, i32 %1, i32 %2, void (i32)* %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca void (i32)*
%9 = alloca [40 x i8]
%10 = alloca i32
%11 = alloca i32
store i64 %0, i64* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store void (i32)* %3, void (i32)** %8
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load void (i32)*, void (i32)** %8
br label %16
16: ; preds = %14, %4
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%18 = load i64, i64* %5
%19 = call i32 @snprintf(i8* %17, i32 39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %18)
%20 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = trunc i64 %21 to i32
store i32 %22, i32* %10
br label %23
23: ; preds = %27, %16
%24 = load i32, i32* %6
%25 = load i32, i32* %10
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load void (i32)*, void (i32)** %8
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
br label %23
31: ; preds = %23
store i32 0, i32* %11
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load void (i32)*, void (i32)** %8
%38 = load i32, i32* %11
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
br label %43
43: ; preds = %36
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 1
store i32 %45, i32* %11
br label %32
46: ; preds = %32
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define void @bc_out_long(i64 %0, i32 %1, i32 %2, void (i32)* nocapture %3) {
%5 = alloca [40 x i8]
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %2, 0
br i1 %7, label %9, label %8
8: ; preds = %4
tail call void %3(i32 32)
br label %9
9: ; preds = %8, %4
%10 = call i32 @snprintf(i8* %6, i32 39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%11 = call i64 @strlen(i8* %6)
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %12, %1
br i1 %13, label %18, label %14
14: ; preds = %18, %9
%15 = icmp sgt i32 %12, 0
br i1 %15, label %16, label %29
16: ; preds = %14
%17 = and i64 %11, 4294967295
br label %22
18: ; preds = %9, %18
%19 = phi i32 [ %20, %18 ], [ %1, %9 ]
%20 = add nsw i32 %19, -1
%21 = icmp sgt i32 %20, %12
br i1 %21, label %18, label %14
22: ; preds = %16, %22
%23 = phi i64 [ 0, %16 ], [ %27, %22 ]
%24 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %17
br i1 %28, label %29, label %22
29: ; preds = %22, %14
ret void
}