#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 */
scalar_t__ sprintf(char *, char *, int, unsigned char *);
unsigned char *strchr(unsigned char *, char);
int b_print(char *buff_orig, char *buff_dest, int tipo, int dmax) {
  register unsigned char *lact = (unsigned char *)buff_orig;
  register unsigned char *lprox = (unsigned char *)buff_orig;
  register int tam = 0;
  while (((lprox = strchr(lact, '\n')) != NULL) && (tam < dmax)) {
    lprox[0] = '\0';
    tam += sprintf(buff_dest + tam, "%d :%s\n", tipo, lact);
    lact = lprox + 1;
  }
  return (tam + 1);
}


x86 assembly (clang, -O0):
<b_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
je     117d <b_print+0x5d>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    118d <b_print+0x6d>
jmp    11d0 <b_print+0xb0>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe53(%rip),%rsi
call   1040 <sprintf@plt>
mov    %rax,%rcx
movslq -0x2c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114d <b_print+0x2d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<b_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     11a4 <b_print+0x84>
test   %r12d,%r12d
jle    11a4 <b_print+0x84>
mov    %rax,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,0x0(%r13)
movslq %ebp,%rbp
lea    (%r15,%rbp,1),%rdi
lea    0xe8d(%rip),%rsi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <sprintf@plt>
add    %eax,%ebp
mov    %r13,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a1 <b_print+0x81>
mov    %rax,%r13
cmp    %r12d,%ebp
jl     1160 <b_print+0x40>
add    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"%d :%s\0A\00"
define i32 @b_print(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%6 = icmp ne i8* %5, null
%7 = icmp sgt i32 %3, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %25
9: ; preds = %4, %9
%10 = phi i8* [ %19, %9 ], [ %5, %4 ]
%11 = phi i32 [ %17, %9 ], [ 0, %4 ]
%12 = phi i8* [ %18, %9 ], [ %0, %4 ]
store i8 0, i8* %10
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = tail call i64 @sprintf(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %12)
%16 = trunc i64 %15 to i32
%17 = add i32 %11, %16
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = tail call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 10)
%20 = icmp ne i8* %19, null
%21 = icmp slt i32 %17, %3
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %9, label %23
23: ; preds = %9
%24 = add i32 %17, 1
br label %25
25: ; preds = %23, %4
%26 = phi i32 [ 1, %4 ], [ %24, %23 ]
ret i32 %26
}