#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 get_line(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int get_N_lines(char *pin, char *w, int N) {
  int len = 0, l = 0, lines = 0;
  char tmp[250];
  w[0] = '\0';
  tmp[0] = '\0';
  while (*pin != '\0' && lines < N) {
    lines++;
    if (lines > 1)
      strcat(w, " \\\\\n");
    l = get_line(pin, tmp, 1);
    strcat(w, tmp);
    len += l + 1;
    pin += l + 1;
  }
  len--;
  pin--;
  return (len);
}


x86 assembly (clang, -O0):
<get_N_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movb   $0x0,-0x120(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x121(%rbp)
je     1180 <get_N_lines+0x60>
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x121(%rbp)
mov    -0x121(%rbp),%al
test   $0x1,%al
jne    1193 <get_N_lines+0x73>
jmp    1203 <get_N_lines+0xe3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jle    11b6 <get_N_lines+0x96>
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x1,%edx
call   1030 <get_line@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1159 <get_N_lines+0x39>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_N_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,0x8(%rsp)
movb   $0x0,(%rsi)
movb   $0x0,0x10(%rsp)
xor    %eax,%eax
cmpb   $0x0,(%rdi)
je     11fb <get_N_lines+0xdb>
mov    %edx,%ebx
test   %edx,%edx
jle    11fb <get_N_lines+0xdb>
mov    %rdi,%rbp
lea    0x10(%rsp),%r15
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <get_line@plt>
mov    %eax,%r12d
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
movslq %r12d,%rcx
lea    0x1(%rcx),%rax
cmpb   $0x0,0x1(%rbp,%rcx,1)
je     11fb <get_N_lines+0xdb>
cmp    $0x2,%ebx
jb     11fb <get_N_lines+0xdb>
add    %rcx,%rbp
add    $0x1,%rbp
mov    $0x2,%r15d
mov    0x8(%rsp),%r14
nopl   (%rax)
mov    %eax,0x4(%rsp)
mov    %r14,%rdi
lea    0xe52(%rip),%rsi
call   1040 <strcat@plt>
mov    %rbp,%rdi
lea    0x10(%rsp),%r13
mov    %r13,%rsi
mov    $0x1,%edx
call   1030 <get_line@plt>
mov    %eax,%r12d
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcat@plt>
movslq %r12d,%rcx
lea    0x1(%rcx),%rax
add    0x4(%rsp),%eax
cmpb   $0x0,0x1(%rbp,%rcx,1)
je     11fb <get_N_lines+0xdb>
add    %rcx,%rbp
add    $0x1,%rbp
lea    0x1(%r15),%ecx
cmp    %ebx,%r15d
mov    %ecx,%r15d
jl     11a0 <get_N_lines+0x80>
add    $0xffffffff,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c" \\\\\0A\00"
define i32 @get_N_lines(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [250 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 0, i8* %12
%13 = getelementptr inbounds [250 x i8], [250 x i8]* %10, i64 0, i64 0
store i8 0, i8* %13
br label %14
14: ; preds = %33, %3
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %9
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br label %23
23: ; preds = %19, %14
%24 = phi i1 [ false, %14 ], [ %22, %19 ]
br i1 %24, label %25, label %49
25: ; preds = %23
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp sgt i32 %28, 1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %30, %25
%34 = load i8*, i8** %4
%35 = getelementptr inbounds [250 x i8], [250 x i8]* %10, i64 0, i64 0
%36 = call i32 @get_line(i8* %34, i8* %35, i32 1)
store i32 %36, i32* %8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds [250 x i8], [250 x i8]* %10, i64 0, i64 0
%39 = call i32 @strcat(i8* %37, i8* %38)
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
%42 = load i32, i32* %7
%43 = add nsw i32 %42, %41
store i32 %43, i32* %7
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
%46 = load i8*, i8** %4
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %4
br label %14
49: ; preds = %23
%50 = load i32, i32* %7
%51 = add nsw i32 %50, -1
store i32 %51, i32* %7
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i32 -1
store i8* %53, i8** %4
%54 = load i32, i32* %7
ret i32 %54
}

LLVM IR (-O2):
@.str = [5 x i8] c" \\\\\0A\00"
define i32 @get_N_lines(i8* %0, i8* %1, i32 %2) {
%4 = alloca [250 x i8]
%5 = getelementptr inbounds [250 x i8], [250 x i8]* %4, i64 0, i64 0
store i8 0, i8* %1
store i8 0, i8* %5
%6 = load i8, i8* %0
%7 = icmp ne i8 %6, 0
%8 = icmp sgt i32 %2, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %36
10: ; preds = %3
%11 = call i32 @get_line(i8* %0, i8* %5, i32 1)
%12 = call i32 @strcat(i8* %1, i8* %5)
%13 = add nsw i32 %11, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
%18 = icmp ugt i32 %2, 1
%19 = and i1 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %10, %20
%21 = phi i32 [ %24, %20 ], [ 1, %10 ]
%22 = phi i32 [ %29, %20 ], [ %13, %10 ]
%23 = phi i8* [ %31, %20 ], [ %15, %10 ]
%24 = add nuw nsw i32 %21, 1
%25 = call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @get_line(i8* %23, i8* %5, i32 1)
%27 = call i32 @strcat(i8* %1, i8* %5)
%28 = add nsw i32 %26, 1
%29 = add nsw i32 %28, %22
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %23, i64 %30
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
%34 = icmp slt i32 %24, %2
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %20, label %36
36: ; preds = %20, %10, %3
%37 = phi i32 [ 0, %3 ], [ %13, %10 ], [ %29, %20 ]
%38 = add nsw i32 %37, -1
ret i32 %38
}