#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
unsigned int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, unsigned int);
void split_lines(const char *s, char *d, unsigned len, int fd) {
  unsigned off = strlen(d);
  while (*s && off + 2 < len) {
    if ((d[off] = *s++) == '\n') {
      d[off + 1] = 0;
      if (!strncmp(d, "INFO ", 5)) {
        printf("%s", d + 5);
        fflush(stdout);
      } else
        write(fd, d, off + 1);
      *d = 0;
      off = 0;
    } else
      off++;
  }
  d[off] = 0;
}


x86 assembly (clang, -O0):
<split_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1196 <split_lines+0x46>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cmp    -0x14(%rbp),%eax
setb   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a6 <split_lines+0x56>
jmp    1255 <split_lines+0x105>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%edx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0xa,%eax
jne    1247 <split_lines+0xf7>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xe18(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1222 <split_lines+0xd2>
mov    -0x10(%rbp),%rsi
add    $0x5,%rsi
lea    0xdfc(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    1234 <split_lines+0xe4>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1040 <write@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
jmp    1250 <split_lines+0x100>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1172 <split_lines+0x22>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%al
test   %al,%al
je     1210 <split_lines+0xc0>
mov    %ebx,%ecx
add    $0x2,%ecx
cmp    %r15d,%ecx
jae    1210 <split_lines+0xc0>
lea    0x5(%r12),%rcx
mov    %rcx,(%rsp)
add    $0x1,%rbp
lea    0xe62(%rip),%r13
xchg   %ax,%ax
mov    %ebx,%ecx
mov    %al,(%r12,%rcx,1)
add    $0x1,%ebx
cmp    $0xa,%al
jne    11fc <split_lines+0xac>
mov    %ebx,%eax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11d7 <split_lines+0x87>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
jmp    11f5 <split_lines+0xa5>
lea    0xe28(%rip),%rdi
mov    (%rsp),%rsi
call   1060 <printf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movb   $0x0,(%r12)
xor    %ebx,%ebx
movzbl 0x0(%rbp),%eax
test   %al,%al
je     1210 <split_lines+0xc0>
lea    0x2(%rbx),%ecx
add    $0x1,%rbp
cmp    %r15d,%ecx
jb     11a0 <split_lines+0x50>
mov    %ebx,%eax
movb   $0x0,(%r12,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"INFO \00"
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
define void @split_lines(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %9
br label %12
12: ; preds = %60, %4
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* %9
%19 = add i32 %18, 2
%20 = load i32, i32* %7
%21 = icmp ult i32 %19, %20
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ false, %12 ], [ %21, %17 ]
br i1 %23, label %24, label %61
24: ; preds = %22
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
%27 = load i8, i8* %25
%28 = load i8*, i8** %6
%29 = load i32, i32* %9
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
%32 = sext i8 %27 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %57
34: ; preds = %24
%35 = load i8*, i8** %6
%36 = load i32, i32* %9
%37 = add i32 %36, 1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %6
%41 = call i32 @strncmp(i8* %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%42 = icmp ne i32 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %34
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 5
%46 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
br label %55
49: ; preds = %34
%50 = load i32, i32* %8
%51 = load i8*, i8** %6
%52 = load i32, i32* %9
%53 = add i32 %52, 1
%54 = call i32 @write(i32 %50, i8* %51, i32 %53)
br label %55
55: ; preds = %49, %43
%56 = load i8*, i8** %6
store i8 0, i8* %56
store i32 0, i32* %9
br label %60
57: ; preds = %24
%58 = load i32, i32* %9
%59 = add i32 %58, 1
store i32 %59, i32* %9
br label %60
60: ; preds = %57, %55
br label %12
61: ; preds = %22
%62 = load i8*, i8** %6
%63 = load i32, i32* %9
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"INFO \00"
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
define void @split_lines(i8* nocapture %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @strlen(i8* %1)
%6 = load i8, i8* %0
%7 = icmp ne i8 %6, 0
%8 = add i32 %5, 2
%9 = icmp ult i32 %8, %2
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %41
11: ; preds = %4
%12 = getelementptr inbounds i8, i8* %1, i64 5
br label %13
13: ; preds = %11, %34
%14 = phi i8 [ %6, %11 ], [ %36, %34 ]
%15 = phi i32 [ %5, %11 ], [ %35, %34 ]
%16 = phi i8* [ %0, %11 ], [ %17, %34 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = zext i32 %15 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 %14, i8* %19
%20 = icmp eq i8 %14, 10
%21 = add i32 %15, 1
br i1 %20, label %22, label %34
22: ; preds = %13
%23 = zext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 0, i8* %24
%25 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%29 = load i32, i32* @stdout
%30 = tail call i32 @fflush(i32 %29)
br label %33
31: ; preds = %22
%32 = tail call i32 @write(i32 %3, i8* %1, i32 %21)
br label %33
33: ; preds = %31, %27
store i8 0, i8* %1
br label %34
34: ; preds = %13, %33
%35 = phi i32 [ 0, %33 ], [ %21, %13 ]
%36 = load i8, i8* %17
%37 = icmp ne i8 %36, 0
%38 = add i32 %35, 2
%39 = icmp ult i32 %38, %2
%40 = select i1 %37, i1 %39, i1 false
br i1 %40, label %13, label %41
41: ; preds = %34, %4
%42 = phi i32 [ %5, %4 ], [ %35, %34 ]
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %1, i64 %43
store i8 0, i8* %44
ret void
}