#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, char);
char feed_buf_write_number(struct feed_buf *const, long);
char feed_esc_write_prefix(struct feed_buf *const);
char feed_esc_write_sgr(struct feed_buf *const p_buf,
                        unsigned char const *const p_attr,
                        unsigned int const i_count) {
  char b_result;
  b_result = feed_esc_write_prefix(p_buf);
  if (b_result) {
    unsigned int i;
    i = 0u;
    while (b_result && (i < i_count)) {
      if (i) {
        b_result = feed_buf_write_character(p_buf, ';');
      }
      if (b_result) {
        b_result = feed_buf_write_number(p_buf, (signed long int)(p_attr[i]));
      }
      i++;
    }
    b_result = feed_buf_write_character(p_buf, 'm');
  }
  return b_result;
}


x86 assembly (clang, -O0):
<feed_esc_write_sgr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <feed_esc_write_prefix@plt>
mov    %al,-0x15(%rbp)
cmpb   $0x0,-0x15(%rbp)
je     11eb <feed_esc_write_sgr+0xbb>
movl   $0x0,-0x1c(%rbp)
movsbl -0x15(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     117e <feed_esc_write_sgr+0x4e>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
setb   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    118e <feed_esc_write_sgr+0x5e>
jmp    11da <feed_esc_write_sgr+0xaa>
cmpl   $0x0,-0x1c(%rbp)
je     11a9 <feed_esc_write_sgr+0x79>
mov    -0x8(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <feed_buf_write_character@plt>
mov    %al,-0x15(%rbp)
cmpb   $0x0,-0x15(%rbp)
je     11cc <feed_esc_write_sgr+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,%esi
call   1050 <feed_buf_write_number@plt>
mov    %al,-0x15(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <feed_esc_write_sgr+0x30>
mov    -0x8(%rbp),%rdi
mov    $0x6d,%esi
call   1040 <feed_buf_write_character@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feed_esc_write_sgr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <feed_esc_write_prefix@plt>
test   %al,%al
je     11b6 <feed_esc_write_sgr+0x86>
test   %ebp,%ebp
je     119f <feed_esc_write_sgr+0x6f>
movzbl (%r14),%esi
mov    %rbx,%rdi
call   1050 <feed_buf_write_number@plt>
test   %al,%al
je     119f <feed_esc_write_sgr+0x6f>
cmp    $0x1,%ebp
je     119f <feed_esc_write_sgr+0x6f>
mov    %ebp,%r15d
mov    $0x2,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1040 <feed_buf_write_character@plt>
test   %al,%al
je     119f <feed_esc_write_sgr+0x6f>
movzbl -0x1(%r14,%rbp,1),%esi
mov    %rbx,%rdi
call   1050 <feed_buf_write_number@plt>
test   %al,%al
je     119f <feed_esc_write_sgr+0x6f>
lea    0x1(%rbp),%rax
cmp    %r15,%rbp
mov    %rax,%rbp
jb     1170 <feed_esc_write_sgr+0x40>
mov    %rbx,%rdi
mov    $0x6d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <feed_buf_write_character@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.feed_buf = type { i32 }
define signext i8 @feed_esc_write_sgr(%struct.feed_buf* %0, i8* %1, i32 %2) {
%4 = alloca %struct.feed_buf*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store %struct.feed_buf* %0, %struct.feed_buf** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load %struct.feed_buf*, %struct.feed_buf** %4
%10 = call signext i8 @feed_esc_write_prefix(%struct.feed_buf* %9)
store i8 %10, i8* %7
%11 = load i8, i8* %7
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %48
13: ; preds = %3
store i32 0, i32* %8
br label %14
14: ; preds = %42, %13
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp ult i32 %19, %20
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ false, %14 ], [ %21, %18 ]
br i1 %23, label %24, label %45
24: ; preds = %22
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load %struct.feed_buf*, %struct.feed_buf** %4
%29 = call signext i8 @feed_buf_write_character(%struct.feed_buf* %28, i8 signext 59)
store i8 %29, i8* %7
br label %30
30: ; preds = %27, %24
%31 = load i8, i8* %7
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load %struct.feed_buf*, %struct.feed_buf** %4
%35 = load i8*, i8** %5
%36 = load i32, i32* %8
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i64
%41 = call signext i8 @feed_buf_write_number(%struct.feed_buf* %34, i64 %40)
store i8 %41, i8* %7
br label %42
42: ; preds = %33, %30
%43 = load i32, i32* %8
%44 = add i32 %43, 1
store i32 %44, i32* %8
br label %14
45: ; preds = %22
%46 = load %struct.feed_buf*, %struct.feed_buf** %4
%47 = call signext i8 @feed_buf_write_character(%struct.feed_buf* %46, i8 signext 109)
store i8 %47, i8* %7
br label %48
48: ; preds = %45, %3
%49 = load i8, i8* %7
ret i8 %49
}

LLVM IR (-O2):
%struct.feed_buf = type { i32 }
define signext i8 @feed_esc_write_sgr(%struct.feed_buf* %0, i8* nocapture %1, i32 %2) {
%4 = tail call signext i8 @feed_esc_write_prefix(%struct.feed_buf* %0)
%5 = icmp eq i8 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %29, label %8
8: ; preds = %6
%9 = zext i32 %2 to i64
%10 = load i8, i8* %1
%11 = zext i8 %10 to i64
%12 = tail call signext i8 @feed_buf_write_number(%struct.feed_buf* %0, i64 %11)
%13 = icmp ne i8 %12, 0
%14 = icmp ne i32 %2, 1
%15 = and i1 %13, %14
br i1 %15, label %16, label %29
16: ; preds = %8, %20
%17 = phi i64 [ %25, %20 ], [ 1, %8 ]
%18 = tail call signext i8 @feed_buf_write_character(%struct.feed_buf* %0, i8 signext 59)
%19 = icmp eq i8 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %1, i64 %17
%22 = load i8, i8* %21
%23 = zext i8 %22 to i64
%24 = tail call signext i8 @feed_buf_write_number(%struct.feed_buf* %0, i64 %23)
%25 = add nuw nsw i64 %17, 1
%26 = icmp ne i8 %24, 0
%27 = icmp ult i64 %25, %9
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %16, label %29
29: ; preds = %16, %20, %8, %6
%30 = tail call signext i8 @feed_buf_write_character(%struct.feed_buf* %0, i8 signext 109)
br label %31
31: ; preds = %29, %3
%32 = phi i8 [ %30, %29 ], [ 0, %3 ]
ret i8 %32
}