#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 */
struct feed_buf {
  int dummy;
};

/* Variables and functions */
char feed_buf_write_character(struct feed_buf *const, unsigned char);
char feed_buf_write_number(struct feed_buf *const p_buf,
                           signed long int const i_data) {
  static unsigned char const g_digit_representation[10u] = {
      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  char b_result;
  unsigned char a_digits[16u];
  unsigned char *p_digits_iterator;
  unsigned int i_digits;
  signed long int i_remainder;
  if (i_data < 0) {
    i_remainder = -i_data;
  } else {
    i_remainder = i_data;
  }
  i_digits = 0;
  p_digits_iterator = a_digits;
  do {
    *(p_digits_iterator) = g_digit_representation[i_remainder % 10];
    i_remainder = (i_remainder / 10);
    p_digits_iterator++;
    i_digits++;
  } while (i_remainder && (i_digits < 16));
  if (i_data < 0) {
    b_result = feed_buf_write_character(p_buf, '-');
  } else {
    b_result = 1;
  }
  if (b_result) {
    do {
      i_digits--;
      p_digits_iterator--;
      b_result = feed_buf_write_character(p_buf, *(p_digits_iterator));
    } while (b_result && (i_digits > 0));
  }
  return b_result;
}


x86 assembly (clang, -O0):
<feed_buf_write_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    113a <feed_buf_write_number+0x2a>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    1142 <feed_buf_write_number+0x32>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
lea    0xe9a(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x48(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x48(%rbp)
mov    %al,-0x49(%rbp)
je     11b0 <feed_buf_write_number+0xa0>
cmpl   $0x10,-0x3c(%rbp)
setb   %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    1151 <feed_buf_write_number+0x41>
cmpq   $0x0,-0x10(%rbp)
jge    11dc <feed_buf_write_number+0xcc>
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1030 <feed_buf_write_character@plt>
mov    %al,-0x11(%rbp)
jmp    11e0 <feed_buf_write_number+0xd0>
movb   $0x1,-0x11(%rbp)
cmpb   $0x0,-0x11(%rbp)
je     1243 <feed_buf_write_number+0x133>
jmp    11ef <feed_buf_write_number+0xdf>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rax
movzbl (%rax),%esi
call   1030 <feed_buf_write_character@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x4a(%rbp)
je     1233 <feed_buf_write_number+0x123>
cmpl   $0x0,-0x3c(%rbp)
seta   %al
mov    %al,-0x4a(%rbp)
mov    -0x4a(%rbp),%al
test   $0x1,%al
jne    11ef <feed_buf_write_number+0xdf>
jmp    1243 <feed_buf_write_number+0x133>
movsbl -0x11(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feed_buf_write_number>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rdx
neg    %rdx
cmovs  %rsi,%rdx
mov    %rdi,%r14
xor    %r10d,%r10d
lea    0xed2(%rip),%r8
movabs $0x6666666666666667,%r9
66 66 66
nopl   0x0(%rax,%rax,1)
mov    %rdx,%rdi
mov    %rdx,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rdi,%rcx
sub    %rax,%rcx
movzbl (%r8,%rcx,1),%eax
mov    %al,(%rsp,%r10,1)
add    $0xfffffffffffffff6,%rdi
lea    0x1(%r10),%rbx
cmp    $0xffffffffffffffec,%rdi
ja     1185 <feed_buf_write_number+0x75>
cmp    $0xf,%r10d
mov    %rbx,%r10
jb     1140 <feed_buf_write_number+0x30>
test   %rsi,%rsi
jns    119b <feed_buf_write_number+0x8b>
mov    %r14,%rdi
mov    $0x2d,%esi
call   1030 <feed_buf_write_character@plt>
test   %al,%al
je     11bd <feed_buf_write_number+0xad>
add    $0xffffffffffffffff,%rbx
nop
movzbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1030 <feed_buf_write_character@plt>
test   %al,%al
je     11bf <feed_buf_write_number+0xaf>
lea    -0x1(%rbx),%rcx
test   %ebx,%ebx
mov    %rcx,%rbx
jne    11a0 <feed_buf_write_number+0x90>
jmp    11bf <feed_buf_write_number+0xaf>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.feed_buf = type { i32 }
@feed_buf_write_number.g_digit_representation = internal constant [10 x i8] c"0123456789"
define signext i8 @feed_buf_write_number(%struct.feed_buf* %0, i64 %1) {
%3 = alloca %struct.feed_buf*
%4 = alloca i64
%5 = alloca i8
%6 = alloca [16 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
store %struct.feed_buf* %0, %struct.feed_buf** %3
store i64 %1, i64* %4
%10 = load i64, i64* %4
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i64, i64* %4
%14 = sub nsw i64 0, %13
store i64 %14, i64* %9
br label %17
15: ; preds = %2
%16 = load i64, i64* %4
store i64 %16, i64* %9
br label %17
17: ; preds = %15, %12
store i32 0, i32* %8
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
store i8* %18, i8** %7
br label %19
19: ; preds = %37, %17
%20 = load i64, i64* %9
%21 = srem i64 %20, 10
%22 = getelementptr inbounds [10 x i8], [10 x i8]* @feed_buf_write_number.g_digit_representation, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %7
store i8 %23, i8* %24
%25 = load i64, i64* %9
%26 = sdiv i64 %25, 10
store i64 %26, i64* %9
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %7
%29 = load i32, i32* %8
%30 = add i32 %29, 1
store i32 %30, i32* %8
br label %31
31: ; preds = %19
%32 = load i64, i64* %9
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %8
%36 = icmp ult i32 %35, 16
br label %37
37: ; preds = %34, %31
%38 = phi i1 [ false, %31 ], [ %36, %34 ]
br i1 %38, label %19, label %39
39: ; preds = %37
%40 = load i64, i64* %4
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load %struct.feed_buf*, %struct.feed_buf** %3
%44 = call signext i8 @feed_buf_write_character(%struct.feed_buf* %43, i8 zeroext 45)
store i8 %44, i8* %5
br label %46
45: ; preds = %39
store i8 1, i8* %5
br label %46
46: ; preds = %45, %42
%47 = load i8, i8* %5
%48 = icmp ne i8 %47, 0
br i1 %48, label %49, label %69
49: ; preds = %46
br label %50
50: ; preds = %66, %49
%51 = load i32, i32* %8
%52 = add i32 %51, -1
store i32 %52, i32* %8
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i32 -1
store i8* %54, i8** %7
%55 = load %struct.feed_buf*, %struct.feed_buf** %3
%56 = load i8*, i8** %7
%57 = load i8, i8* %56
%58 = call signext i8 @feed_buf_write_character(%struct.feed_buf* %55, i8 zeroext %57)
store i8 %58, i8* %5
br label %59
59: ; preds = %50
%60 = load i8, i8* %5
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i32, i32* %8
%65 = icmp ugt i32 %64, 0
br label %66
66: ; preds = %63, %59
%67 = phi i1 [ false, %59 ], [ %65, %63 ]
br i1 %67, label %50, label %68
68: ; preds = %66
br label %69
69: ; preds = %68, %46
%70 = load i8, i8* %5
ret i8 %70
}

LLVM IR (-O2):
%struct.feed_buf = type { i32 }
@feed_buf_write_number.g_digit_representation = internal unnamed_addr constant [10 x i8] c"0123456789"
define signext i8 @feed_buf_write_number(%struct.feed_buf* %0, i64 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = icmp slt i64 %1, 0
%6 = sub nsw i64 0, %1
%7 = select i1 %5, i64 %6, i64 %1
br label %8
8: ; preds = %8, %2
%9 = phi i8* [ %4, %2 ], [ %16, %8 ]
%10 = phi i32 [ 0, %2 ], [ %17, %8 ]
%11 = phi i64 [ %7, %2 ], [ %15, %8 ]
%12 = srem i64 %11, 10
%13 = getelementptr inbounds [10 x i8], [10 x i8]* @feed_buf_write_number.g_digit_representation, i64 0, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %9
%15 = sdiv i64 %11, 10
%16 = getelementptr inbounds i8, i8* %9, i64 1
%17 = add nuw nsw i32 %10, 1
%18 = add nsw i64 %11, -10
%19 = icmp ult i64 %18, -19
%20 = icmp ult i32 %10, 15
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %8, label %22
22: ; preds = %8
br i1 %5, label %23, label %26
23: ; preds = %22
%24 = tail call signext i8 @feed_buf_write_character(%struct.feed_buf* %0, i8 zeroext 45)
%25 = icmp eq i8 %24, 0
br i1 %25, label %37, label %26
26: ; preds = %23, %22
br label %27
27: ; preds = %26, %27
%28 = phi i8* [ %31, %27 ], [ %16, %26 ]
%29 = phi i32 [ %30, %27 ], [ %17, %26 ]
%30 = add nsw i32 %29, -1
%31 = getelementptr inbounds i8, i8* %28, i64 -1
%32 = load i8, i8* %31
%33 = tail call signext i8 @feed_buf_write_character(%struct.feed_buf* %0, i8 zeroext %32)
%34 = icmp ne i8 %33, 0
%35 = icmp ne i32 %30, 0
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %27, label %37
37: ; preds = %27, %23
%38 = phi i8 [ 0, %23 ], [ %33, %27 ]
ret i8 %38
}