#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 katcp_dispatch {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ add_client_server_katcp(struct katcp_dispatch *, int,
                                           char *);
unsigned int allocate_clients_shared_katcp(struct katcp_dispatch *,
                                           unsigned int);
scalar_t__ clone_katcp(struct katcp_dispatch *);
int pipe_from_file_katcp(struct katcp_dispatch *, char *);
scalar_t__ prepare_core_loop_katcp(struct katcp_dispatch *);
int run_core_loop_katcp(struct katcp_dispatch *);
int terminate_katcp(struct katcp_dispatch *, int);
int run_pipe_server_katcp(struct katcp_dispatch *dl, char *file, int pfd) {
  int fd;
  unsigned int need;
  if (pfd < 0) {
    return terminate_katcp(dl, 10);
  }
  need = file ? 2 : 1;
  if (allocate_clients_shared_katcp(dl, need) < need) {
    return terminate_katcp(dl, 10);
  }
  if (prepare_core_loop_katcp(dl) < 0) {
    return terminate_katcp(dl, 10);
  }
  if (file) {
    fd = pipe_from_file_katcp(dl, file);
    if (fd < 0) {
      return terminate_katcp(dl, 10);
    }
    add_client_server_katcp(dl, fd, file);
  }
  if (clone_katcp(dl)) {
    add_client_server_katcp(dl, pfd, "-");
  } else {
    return terminate_katcp(dl, 10);
  }
  return run_core_loop_katcp(dl);
}


x86 assembly (clang, -O0):
<run_pipe_server_katcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a3 <run_pipe_server_katcp+0x33>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <terminate_katcp@plt>
mov    %eax,-0x4(%rbp)
jmp    12a7 <run_pipe_server_katcp+0x137>
mov    -0x18(%rbp),%rdx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1090 <allocate_clients_shared_katcp@plt>
cmp    -0x24(%rbp),%eax
jae    11e6 <run_pipe_server_katcp+0x76>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <terminate_katcp@plt>
mov    %eax,-0x4(%rbp)
jmp    12a7 <run_pipe_server_katcp+0x137>
mov    -0x10(%rbp),%rdi
call   1040 <prepare_core_loop_katcp@plt>
cmp    $0x0,%rax
jge    120f <run_pipe_server_katcp+0x9f>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <terminate_katcp@plt>
mov    %eax,-0x4(%rbp)
jmp    12a7 <run_pipe_server_katcp+0x137>
cmpq   $0x0,-0x18(%rbp)
je     125a <run_pipe_server_katcp+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <pipe_from_file_katcp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    124a <run_pipe_server_katcp+0xda>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <terminate_katcp@plt>
mov    %eax,-0x4(%rbp)
jmp    12a7 <run_pipe_server_katcp+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1080 <add_client_server_katcp@plt>
mov    -0x10(%rbp),%rdi
call   1070 <clone_katcp@plt>
cmp    $0x0,%rax
je     1285 <run_pipe_server_katcp+0x115>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    0xd85(%rip),%rdx
call   1080 <add_client_server_katcp@plt>
jmp    129b <run_pipe_server_katcp+0x12b>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <terminate_katcp@plt>
mov    %eax,-0x4(%rbp)
jmp    12a7 <run_pipe_server_katcp+0x137>
mov    -0x10(%rbp),%rdi
call   1060 <run_core_loop_katcp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_pipe_server_katcp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %edx,%edx
js     11fd <run_pipe_server_katcp+0x8d>
mov    %edx,%r14d
mov    %rsi,%r15
cmp    $0x1,%rsi
mov    $0x2,%ebp
sbb    $0x0,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1090 <allocate_clients_shared_katcp@plt>
cmp    %ebp,%eax
jb     11fd <run_pipe_server_katcp+0x8d>
mov    %rbx,%rdi
call   1040 <prepare_core_loop_katcp@plt>
test   %rax,%rax
js     11fd <run_pipe_server_katcp+0x8d>
test   %r15,%r15
je     11cc <run_pipe_server_katcp+0x5c>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <pipe_from_file_katcp@plt>
test   %eax,%eax
js     11fd <run_pipe_server_katcp+0x8d>
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1080 <add_client_server_katcp@plt>
mov    %rbx,%rdi
call   1070 <clone_katcp@plt>
test   %rax,%rax
je     11fd <run_pipe_server_katcp+0x8d>
lea    0xe20(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <add_client_server_katcp@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <run_core_loop_katcp@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <terminate_katcp@plt>

LLVM IR (-O0):
%struct.katcp_dispatch = type { i32 }
@.str = [2 x i8] c"-\00"
define i32 @run_pipe_server_katcp(%struct.katcp_dispatch* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.katcp_dispatch*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.katcp_dispatch* %0, %struct.katcp_dispatch** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%14 = call i32 @terminate_katcp(%struct.katcp_dispatch* %13, i32 10)
store i32 %14, i32* %4
br label %66
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 2, i32 1
store i32 %19, i32* %9
%20 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%21 = load i32, i32* %9
%22 = call i32 @allocate_clients_shared_katcp(%struct.katcp_dispatch* %20, i32 %21)
%23 = load i32, i32* %9
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%27 = call i32 @terminate_katcp(%struct.katcp_dispatch* %26, i32 10)
store i32 %27, i32* %4
br label %66
28: ; preds = %15
%29 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%30 = call i64 @prepare_core_loop_katcp(%struct.katcp_dispatch* %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%34 = call i32 @terminate_katcp(%struct.katcp_dispatch* %33, i32 10)
store i32 %34, i32* %4
br label %66
35: ; preds = %28
%36 = load i8*, i8** %6
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %52
38: ; preds = %35
%39 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%40 = load i8*, i8** %6
%41 = call i32 @pipe_from_file_katcp(%struct.katcp_dispatch* %39, i8* %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%46 = call i32 @terminate_katcp(%struct.katcp_dispatch* %45, i32 10)
store i32 %46, i32* %4
br label %66
47: ; preds = %38
%48 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%49 = load i32, i32* %8
%50 = load i8*, i8** %6
%51 = call i32 @add_client_server_katcp(%struct.katcp_dispatch* %48, i32 %49, i8* %50)
br label %52
52: ; preds = %47, %35
%53 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%54 = call i64 @clone_katcp(%struct.katcp_dispatch* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%58 = load i32, i32* %7
%59 = call i32 @add_client_server_katcp(%struct.katcp_dispatch* %57, i32 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %63
60: ; preds = %52
%61 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%62 = call i32 @terminate_katcp(%struct.katcp_dispatch* %61, i32 10)
store i32 %62, i32* %4
br label %66
63: ; preds = %56
%64 = load %struct.katcp_dispatch*, %struct.katcp_dispatch** %5
%65 = call i32 @run_core_loop_katcp(%struct.katcp_dispatch* %64)
store i32 %65, i32* %4
br label %66
66: ; preds = %63, %60, %44, %32, %25, %12
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
%struct.katcp_dispatch = type { i32 }
@.str = [2 x i8] c"-\00"
define i32 @run_pipe_server_katcp(%struct.katcp_dispatch* %0, i8* %1, i32 %2) {
%4 = icmp slt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @terminate_katcp(%struct.katcp_dispatch* %0, i32 10)
br label %35
7: ; preds = %3
%8 = icmp eq i8* %1, null
%9 = select i1 %8, i32 1, i32 2
%10 = tail call i32 @allocate_clients_shared_katcp(%struct.katcp_dispatch* %0, i32 %9)
%11 = icmp ult i32 %10, %9
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @terminate_katcp(%struct.katcp_dispatch* %0, i32 10)
br label %35
14: ; preds = %7
%15 = tail call i64 @prepare_core_loop_katcp(%struct.katcp_dispatch* %0)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @terminate_katcp(%struct.katcp_dispatch* %0, i32 10)
br label %35
19: ; preds = %14
br i1 %8, label %27, label %20
20: ; preds = %19
%21 = tail call i32 @pipe_from_file_katcp(%struct.katcp_dispatch* %0, i8* %1)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @terminate_katcp(%struct.katcp_dispatch* %0, i32 10)
br label %35
25: ; preds = %20
%26 = tail call i32 @add_client_server_katcp(%struct.katcp_dispatch* %0, i32 %21, i8* %1)
br label %27
27: ; preds = %25, %19
%28 = tail call i64 @clone_katcp(%struct.katcp_dispatch* %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = tail call i32 @add_client_server_katcp(%struct.katcp_dispatch* %0, i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 @run_core_loop_katcp(%struct.katcp_dispatch* %0)
br label %35
33: ; preds = %27
%34 = tail call i32 @terminate_katcp(%struct.katcp_dispatch* %0, i32 10)
br label %35
35: ; preds = %30, %33, %23, %17, %12, %5
%36 = phi i32 [ %6, %5 ], [ %13, %12 ], [ %18, %17 ], [ %24, %23 ], [ %32, %30 ], [ %34, %33 ]
ret i32 %36
}