#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct aquaria {
  int dummy;
};
typedef int /*<<< orphan*/ sin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_LOOPBACK;
struct aquaria *aq_connect(struct sockaddr const *, int);
int /*<<< orphan*/ aq_free(struct aquaria *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ menu_setup(struct aquaria *);
int ui_mainloop(struct aquaria *, void *);
void *ui_open(int, char **);
int main(int argc, char **argv) {
  int err;
  struct aquaria *aq;
  struct sockaddr_in sin;
  void *ui;
  sin.sin_family = AF_INET;
  sin.sin_port = htons(4444);
  sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  aq = aq_connect((const struct sockaddr *)&sin, sizeof(sin));
  menu_setup(aq);
  ui = ui_open(argc, argv);
  if (ui == NULL)
    return EXIT_FAILURE;
  err = ui_mainloop(aq, ui);
  aq_free(aq);
  if (err < 0)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x115c,%edi
call   1050 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1030 <aq_connect@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <menu_setup@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1090 <ui_open@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11f7 <main+0x87>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <main+0xc7>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <ui_mainloop@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <aq_free@plt>
cmpl   $0x0,-0x14(%rbp)
jge    122b <main+0xbb>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1237 <main+0xc7>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0x115c,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,(%rsp)
mov    %rsp,%rdi
mov    $0xc,%esi
call   1030 <aq_connect@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <menu_setup@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1090 <ui_open@plt>
test   %rax,%rax
je     11e9 <main+0x79>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <ui_mainloop@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <aq_free@plt>
test   %ebp,%ebp
jns    11f2 <main+0x82>
mov    0x2de0(%rip),%rax
jmp    11f9 <main+0x89>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.aquaria = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.aquaria*
%8 = alloca %struct.sockaddr_in
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @htons(i32 4444)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_LOOPBACK
%15 = call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%19 = call %struct.aquaria* @aq_connect(%struct.sockaddr* %18, i32 12)
store %struct.aquaria* %19, %struct.aquaria** %7
%20 = load %struct.aquaria*, %struct.aquaria** %7
%21 = call i32 @menu_setup(%struct.aquaria* %20)
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = call i8* @ui_open(i32 %22, i8** %23)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %2
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %41
29: ; preds = %2
%30 = load %struct.aquaria*, %struct.aquaria** %7
%31 = load i8*, i8** %9
%32 = call i32 @ui_mainloop(%struct.aquaria* %30, i8* %31)
store i32 %32, i32* %6
%33 = load %struct.aquaria*, %struct.aquaria** %7
%34 = call i32 @aq_free(%struct.aquaria* %33)
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %3
br label %41
39: ; preds = %29
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %3
br label %41
41: ; preds = %39, %37, %27
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
%struct.aquaria = type { i32 }
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %5, i32* %6
%7 = tail call i32 @htons(i32 4444)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @INADDR_LOOPBACK
%10 = tail call i32 @htonl(i32 %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %10, i32* %11
%12 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%13 = call %struct.aquaria* @aq_connect(%struct.sockaddr* %12, i32 12)
%14 = call i32 @menu_setup(%struct.aquaria* %13)
%15 = call i8* @ui_open(i32 %0, i8** %1)
%16 = icmp eq i8* %15, null
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = call i32 @ui_mainloop(%struct.aquaria* %13, i8* %15)
%19 = call i32 @aq_free(%struct.aquaria* %13)
%20 = icmp slt i32 %18, 0
%21 = select i1 %20, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %22
22: ; preds = %17, %2
%23 = phi i32* [ @EXIT_FAILURE, %2 ], [ %21, %17 ]
%24 = load i32, i32* %23
ret i32 %24
}