#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 sockaddr_in {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int io_dispatch(int, struct sockaddr_in *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int parse_opts(int, char **, struct sockaddr_in *, int *);
int sock_alloc(int, struct sockaddr_in *);
int main(int argc, char **argv) {
  int sockfd;
  int listen = 0;
  struct sockaddr_in addr;
  int rc = 0;
  memset(&addr, 0, sizeof(addr));
  rc = parse_opts(argc, argv, &addr, &listen);
  if (rc) {
    return rc;
  }
  sockfd = sock_alloc(listen, &addr);
  if (sockfd < 0)
    return -1;
  rc = io_dispatch(sockfd, listen ? NULL : &addr);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1030 <parse_opts@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b0 <main+0x60>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <main+0xcb>
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <sock_alloc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <main+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <main+0xcb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f0 <main+0xa0>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11fd <main+0xad>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11fd <main+0xad>
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1070 <io_dispatch@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <parse_opts@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11cb <main+0x7b>
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1060 <sock_alloc@plt>
test   %eax,%eax
js     11c6 <main+0x76>
mov    %eax,%ebp
xor    %ebx,%ebx
cmpl   $0x0,0x4(%rsp)
cmovne %rbx,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <io_dispatch@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11cb <main+0x7b>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
%10 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 4)
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @parse_opts(i32 %11, i8** %12, %struct.sockaddr_in* %8, i32* %7)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %9
store i32 %17, i32* %3
br label %35
18: ; preds = %2
%19 = load i32, i32* %7
%20 = call i32 @sock_alloc(i32 %19, %struct.sockaddr_in* %8)
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 i32 -1, i32* %3
br label %35
24: ; preds = %18
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
br label %30
29: ; preds = %24
br label %30
30: ; preds = %29, %28
%31 = phi %struct.sockaddr_in* [ null, %28 ], [ %8, %29 ]
%32 = call i32 @io_dispatch(i32 %25, %struct.sockaddr_in* %31)
store i32 %32, i32* %9
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
store i32 0, i32* %3
br label %35
35: ; preds = %30, %23, %16
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 4)
%8 = call i32 @parse_opts(i32 %0, i8** %1, %struct.sockaddr_in* %4, i32* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %2
%11 = load i32, i32* %3
%12 = call i32 @sock_alloc(i32 %11, %struct.sockaddr_in* %4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, %struct.sockaddr_in* %4, %struct.sockaddr_in* null
%18 = call i32 @io_dispatch(i32 %12, %struct.sockaddr_in* %17)
%19 = call i32 @close(i32 %12)
br label %20
20: ; preds = %10, %2, %14
%21 = phi i32 [ 0, %14 ], [ %8, %2 ], [ -1, %10 ]
ret i32 %21
}