#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 */
struct katcl_line *create_katcl(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int net_connect(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
struct katcl_line *initiate_connection(char *server, int verbose) {
  struct katcl_line *l;
  int fd, flags;
  flags = 0;
  if (verbose > 0) {
    flags = 0x1;
    if (verbose > 1) {
      flags = 0x2;
    }
  }
  fd = net_connect(server, 0, flags);
  if (fd < 0) {
    if (verbose > 0) {
      fprintf(stderr, "%s: unable to initiate connection to %s\n", "sq",
              server);
    }
    return NULL;
  }
  l = create_katcl(fd);
  if (l == NULL) {
    if (verbose > 0) {
      fprintf(stderr, "%s: unable to allocate state\n", "sq");
    }
    return NULL;
  }
  return l;
}


x86 assembly (clang, -O0):
<initiate_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    116d <initiate_connection+0x3d>
movl   $0x1,-0x28(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1168 <initiate_connection+0x38>
movl   $0x2,-0x28(%rbp)
jmp    116d <initiate_connection+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
xor    %esi,%esi
call   1030 <net_connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11c1 <initiate_connection+0x91>
cmpl   $0x0,-0x14(%rbp)
jle    11b4 <initiate_connection+0x84>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xe5a(%rip),%rsi
lea    0xe7c(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1215 <initiate_connection+0xe5>
mov    -0x24(%rbp),%edi
call   1050 <create_katcl@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    120d <initiate_connection+0xdd>
cmpl   $0x0,-0x14(%rbp)
jle    1200 <initiate_connection+0xd0>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
lea    0xe30(%rip),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1215 <initiate_connection+0xe5>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initiate_connection>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
cmp    $0x1,%esi
sete   %al
mov    $0x2,%edx
sub    %eax,%edx
xor    %eax,%eax
test   %esi,%esi
cmovle %eax,%edx
xor    %esi,%esi
call   1030 <net_connect@plt>
test   %eax,%eax
js     118f <initiate_connection+0x5f>
mov    %eax,%edi
call   1050 <create_katcl@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11ba <initiate_connection+0x8a>
test   %rbx,%rbx
jne    11ba <initiate_connection+0x8a>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
lea    0xea5(%rip),%rdx
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ba <initiate_connection+0x8a>
test   %ebp,%ebp
jle    11b8 <initiate_connection+0x88>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
lea    0xe7f(%rip),%rdx
xor    %ebx,%ebx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ba <initiate_connection+0x8a>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.katcl_line = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"%s: unable to initiate connection to %s\0A\00"
@.str.1 = [3 x i8] c"sq\00"
@.str.2 = [30 x i8] c"%s: unable to allocate state\0A\00"
define %struct.katcl_line* @initiate_connection(i8* %0, i32 %1) {
%3 = alloca %struct.katcl_line*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.katcl_line*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
store i32 1, i32* %8
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 2, i32* %8
br label %15
15: ; preds = %14, %11
br label %16
16: ; preds = %15, %2
%17 = load i8*, i8** %4
%18 = load i32, i32* %8
%19 = call i32 @net_connect(i8* %17, i32 0, i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %4
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %25, %22
store %struct.katcl_line* null, %struct.katcl_line** %3
br label %44
30: ; preds = %16
%31 = load i32, i32* %7
%32 = call %struct.katcl_line* @create_katcl(i32 %31)
store %struct.katcl_line* %32, %struct.katcl_line** %6
%33 = load %struct.katcl_line*, %struct.katcl_line** %6
%34 = icmp eq %struct.katcl_line* %33, null
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i32, i32* %5
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %38, %35
store %struct.katcl_line* null, %struct.katcl_line** %3
br label %44
42: ; preds = %30
%43 = load %struct.katcl_line*, %struct.katcl_line** %6
store %struct.katcl_line* %43, %struct.katcl_line** %3
br label %44
44: ; preds = %42, %41, %29
%45 = load %struct.katcl_line*, %struct.katcl_line** %3
ret %struct.katcl_line* %45
}

LLVM IR (-O2):
%struct.katcl_line = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"%s: unable to initiate connection to %s\0A\00"
@.str.1 = [3 x i8] c"sq\00"
@.str.2 = [30 x i8] c"%s: unable to allocate state\0A\00"
define %struct.katcl_line* @initiate_connection(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = icmp eq i32 %1, 1
%5 = select i1 %4, i32 1, i32 2
%6 = select i1 %3, i32 %5, i32 0
%7 = tail call i32 @net_connect(i8* %0, i32 0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
br i1 %3, label %10, label %20
10: ; preds = %9
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
13: ; preds = %2
%14 = tail call %struct.katcl_line* @create_katcl(i32 %7)
%15 = icmp eq %struct.katcl_line* %14, null
%16 = and i1 %3, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %13, %17, %9, %10
%21 = phi %struct.katcl_line* [ null, %10 ], [ null, %9 ], [ null, %17 ], [ %14, %13 ]
ret %struct.katcl_line* %21
}