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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ close(int);
struct katcl_line *create_katcl(int);
int dup(int /*<<< orphan*/);
int net_connect(char *, int /*<<< orphan*/, int);
struct katcl_line *create_extended_rpc_katcl(char *name, int flags) {
  int fd;
  struct katcl_line *l;
  if (name) {
    fd = net_connect(name, 0, flags);
    if (fd < 0) {
      return NULL;
    }
  } else {
    fd = dup(STDIN_FILENO);
    if (fd < 0) {
      return NULL;
    }
  }
  l = create_katcl(fd);
  if (l == NULL) {
    close(fd);
    return NULL;
  }
  return l;
}


x86 assembly (clang, -O0):
<create_extended_rpc_katcl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1187 <create_extended_rpc_katcl+0x47>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <net_connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1182 <create_extended_rpc_katcl+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11e8 <create_extended_rpc_katcl+0xa8>
jmp    11b4 <create_extended_rpc_katcl+0x74>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1030 <dup@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11af <create_extended_rpc_katcl+0x6f>
movq   $0x0,-0x8(%rbp)
jmp    11e8 <create_extended_rpc_katcl+0xa8>
jmp    11b4 <create_extended_rpc_katcl+0x74>
mov    -0x18(%rbp),%edi
call   1060 <create_katcl@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e0 <create_extended_rpc_katcl+0xa0>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e8 <create_extended_rpc_katcl+0xa8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_extended_rpc_katcl>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     115b <create_extended_rpc_katcl+0x1b>
mov    %esi,%edx
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <net_connect@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    116f <create_extended_rpc_katcl+0x2f>
jmp    1187 <create_extended_rpc_katcl+0x47>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
call   1030 <dup@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1185 <create_extended_rpc_katcl+0x45>
mov    %ebp,%edi
call   1060 <create_katcl@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1187 <create_extended_rpc_katcl+0x47>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
@STDIN_FILENO = global i32 0
define %struct.katcl_line* @create_extended_rpc_katcl(i8* %0, i32 %1) {
%3 = alloca %struct.katcl_line*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.katcl_line*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @net_connect(i8* %11, i32 0, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store %struct.katcl_line* null, %struct.katcl_line** %3
br label %35
17: ; preds = %10
br label %25
18: ; preds = %2
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @dup(i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store %struct.katcl_line* null, %struct.katcl_line** %3
br label %35
24: ; preds = %18
br label %25
25: ; preds = %24, %17
%26 = load i32, i32* %6
%27 = call %struct.katcl_line* @create_katcl(i32 %26)
store %struct.katcl_line* %27, %struct.katcl_line** %7
%28 = load %struct.katcl_line*, %struct.katcl_line** %7
%29 = icmp eq %struct.katcl_line* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
store %struct.katcl_line* null, %struct.katcl_line** %3
br label %35
33: ; preds = %25
%34 = load %struct.katcl_line*, %struct.katcl_line** %7
store %struct.katcl_line* %34, %struct.katcl_line** %3
br label %35
35: ; preds = %33, %30, %23, %16
%36 = load %struct.katcl_line*, %struct.katcl_line** %3
ret %struct.katcl_line* %36
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
@STDIN_FILENO = global i32 0
define %struct.katcl_line* @create_extended_rpc_katcl(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @net_connect(i8* %0, i32 0, i32 %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %17, label %11
7: ; preds = %2
%8 = load i32, i32* @STDIN_FILENO
%9 = tail call i32 @dup(i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %7, %4
%12 = phi i32 [ %5, %4 ], [ %9, %7 ]
%13 = tail call %struct.katcl_line* @create_katcl(i32 %12)
%14 = icmp eq %struct.katcl_line* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = tail call i32 @close(i32 %12)
br label %17
17: ; preds = %11, %7, %4, %15
%18 = phi %struct.katcl_line* [ null, %15 ], [ null, %4 ], [ null, %7 ], [ %13, %11 ]
ret %struct.katcl_line* %18
}