#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ close(int);
int /*<<< orphan*/ exec_piped(int *, int *, int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ write_exactly(int, char *, int);
pid_t start_process(char **lines, int count, int *in, int *out, int *err) {
  pid_t pid = exec_piped(in, out, err);
  for (int j = 0; j < count; j++) {
    int len = strlen(lines[j]);
    write_exactly(*in, lines[j], len);
  }
  for (; !(close(*in) == 0); exit(EXIT_FAILURE))
    ;
  return pid;
}


x86 assembly (clang, -O0):
<start_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <exec_piped@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ce <start_process+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x34(%rbp),%edx
call   1060 <write_exactly@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1186 <start_process+0x36>
jmp    11d3 <start_process+0x83>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
sete   %al
xor    $0xff,%al
test   $0x1,%al
jne    11f4 <start_process+0xa4>
jmp    1207 <start_process+0xb7>
jmp    11f9 <start_process+0xa9>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_process>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
mov    %rdx,%rdi
mov    %rcx,%rsi
mov    %r8,%rdx
call   1050 <exec_piped@plt>
mov    %eax,%r14d
test   %r15d,%r15d
jle    11a3 <start_process+0x53>
mov    %r15d,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x0(%rbp,%rbx,8),%rdi
call   1030 <strlen@plt>
mov    (%r12),%edi
mov    0x0(%rbp,%rbx,8),%rsi
mov    %eax,%edx
call   1060 <write_exactly@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <start_process+0x30>
mov    (%r12),%edi
call   1040 <close@plt>
test   %rax,%rax
jne    11bd <start_process+0x6d>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
define i32 @start_process(i8** %0, i32 %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8** %0, i8*** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%14 = load i32*, i32** %8
%15 = load i32*, i32** %9
%16 = load i32*, i32** %10
%17 = call i32 @exec_piped(i32* %14, i32* %15, i32* %16)
store i32 %17, i32* %11
store i32 0, i32* %12
br label %18
18: ; preds = %38, %5
%19 = load i32, i32* %12
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %41
22: ; preds = %18
%23 = load i8**, i8*** %6
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %13
%29 = load i32*, i32** %8
%30 = load i32, i32* %29
%31 = load i8**, i8*** %6
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = load i32, i32* %13
%37 = call i32 @write_exactly(i32 %30, i8* %35, i32 %36)
br label %38
38: ; preds = %22
%39 = load i32, i32* %12
%40 = add nsw i32 %39, 1
store i32 %40, i32* %12
br label %18
41: ; preds = %18
br label %42
42: ; preds = %41
%43 = load i32*, i32** %8
%44 = load i32, i32* %43
%45 = call i64 @close(i32 %44)
%46 = icmp eq i64 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %52
48: ; preds = %42
br label %49
49: ; preds = %48
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42
%53 = load i32, i32* %11
ret i32 %53
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
define i32 @start_process(i8** nocapture %0, i32 %1, i32* %2, i32* %3, i32* %4) {
%6 = tail call i32 @exec_piped(i32* %2, i32* %3, i32* %4)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = zext i32 %1 to i64
br label %14
10: ; preds = %14, %5
%11 = load i32, i32* %2
%12 = tail call i64 @close(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %27, label %24
14: ; preds = %8, %14
%15 = phi i64 [ 0, %8 ], [ %22, %14 ]
%16 = getelementptr inbounds i8*, i8** %0, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i32 @strlen(i8* %17)
%19 = load i32, i32* %2
%20 = load i8*, i8** %16
%21 = tail call i32 @write_exactly(i32 %19, i8* %20, i32 %18)
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, %9
br i1 %23, label %10, label %14
24: ; preds = %10
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %10
ret i32 %6
}