#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*/ sprintf(char *, char *, long);
int 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, idx;
  if (space)
    (*out_char)(' ');
  sprintf(digits, "%ld", val);
  len = strlen(digits);
  while (size > len) {
    (*out_char)('0');
    size--;
  }
  for (idx = 0; idx < len; idx++)
    (*out_char)(digits[idx]);
}


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),%rdx
lea    0xea9(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x44(%rbp),%eax
jle    118a <bc_out_long+0x6a>
mov    $0x30,%edi
call   *-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1168 <bc_out_long+0x48>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    11ba <bc_out_long+0x9a>
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    1191 <bc_out_long+0x71>
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),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <sprintf@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
cmp    %ebp,%eax
jge    1180 <bc_out_long+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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 @sprintf(i8* %17, 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 i32 @strlen(i8* %20)
store i32 %21, i32* %10
br label %22
22: ; preds = %26, %16
%23 = load i32, i32* %6
%24 = load i32, i32* %10
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load void (i32)*, void (i32)** %8
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
br label %22
30: ; preds = %22
store i32 0, i32* %11
br label %31
31: ; preds = %42, %30
%32 = load i32, i32* %11
%33 = load i32, i32* %10
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load void (i32)*, void (i32)** %8
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
br label %42
42: ; preds = %35
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %31
45: ; preds = %31
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 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%11 = call i32 @strlen(i8* %6)
%12 = icmp slt i32 %11, %1
br i1 %12, label %17, label %13
13: ; preds = %17, %9
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %28
15: ; preds = %13
%16 = zext i32 %11 to i64
br label %21
17: ; preds = %9, %17
%18 = phi i32 [ %19, %17 ], [ %1, %9 ]
%19 = add nsw i32 %18, -1
%20 = icmp sgt i32 %19, %11
br i1 %20, label %17, label %13
21: ; preds = %15, %21
%22 = phi i64 [ 0, %15 ], [ %26, %21 ]
%23 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %16
br i1 %27, label %28, label %21
28: ; preds = %21, %13
ret void
}