#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__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ my_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
unsigned int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
scalar_t__ listen(int, unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in my_addr;
  unsigned int myport, lisnum;
  if (argc != 4) {
    usage();
  }
  if (argv[1]) {
    myport = atoi(argv[1]);
  } else {
    myport = 7878;
  }
  if (argv[2]) {
    lisnum = atoi(argv[2]);
  } else {
    lisnum = 5;
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket failed!");
    exit(errno);
  }
  bzero(&my_addr, sizeof(my_addr));
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(myport);
  if (argv[3]) {
    inet_aton(argv[3], (struct in_addr *)my_addr.sin_addr.s_addr);
  } else {
    my_addr.sin_addr.s_addr = INADDR_ANY;
  }
  if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr)) == -1) {
    perror("bind failed!");
    exit(errno);
  }
  if (listen(sockfd, lisnum) != 0) {
    perror("listen failed!");
    exit(errno);
  } else {
    printf("Listen Begin!\n");
  }
  sleep(10);
  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)
cmpl   $0x4,-0x8(%rbp)
je     11e7 <main+0x27>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     120b <main+0x4b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
jmp    1212 <main+0x52>
movl   $0x1ec6,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1236 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    123d <main+0x7d>
movl   $0x5,-0x30(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    127c <main+0xbc>
lea    0xd97(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     12c6 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <inet_aton@plt>
jmp    12d4 <main+0x114>
mov    0x2d13(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
jne    1308 <main+0x148>
lea    0xd1a(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
je     1337 <main+0x177>
lea    0xcf8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xced(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
je     11db <main+0x1b>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     11ee <main+0x2e>
call   10b0 <atoi@plt>
mov    %eax,%r15d
jmp    11f4 <main+0x34>
mov    $0x1ec6,%r15d
mov    0x10(%rbx),%rdi
test   %rdi,%rdi
je     1207 <main+0x47>
call   10b0 <atoi@plt>
mov    %eax,%r14d
jmp    120d <main+0x4d>
mov    $0x5,%r14d
mov    0x2dd4(%rip),%r12
mov    (%r12),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     12be <main+0xfe>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    $0x10,%esi
call   10a0 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0xc(%rsp)
mov    %r15d,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x18(%rbx),%rdi
test   %rdi,%rdi
je     1268 <main+0xa8>
mov    (%rsp),%rsi
call   1050 <inet_aton@plt>
jmp    1276 <main+0xb6>
mov    0x2d71(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1080 <bind@plt>
cmp    $0xffffffff,%eax
je     12c7 <main+0x107>
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <listen@plt>
test   %rax,%rax
jne    12d0 <main+0x110>
lea    0xd8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3b(%rip),%rdi
jmp    12d7 <main+0x117>
lea    0xd41(%rip),%rdi
jmp    12d7 <main+0x117>
lea    0xd45(%rip),%rdi
call   1090 <perror@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"socket failed!\00"
@errno = global i32 0
@INADDR_ANY = global i64 0
@.str.1 = [13 x i8] c"bind failed!\00"
@.str.2 = [15 x i8] c"listen failed!\00"
@.str.3 = [15 x i8] c"Listen Begin!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
br label %14
14: ; preds = %12, %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
br label %25
24: ; preds = %14
store i32 7878, i32* %8
br label %25
25: ; preds = %24, %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %9
br label %36
35: ; preds = %25
store i32 5, i32* %9
br label %36
36: ; preds = %35, %30
%37 = load i32, i32* @AF_INET
%38 = load i32, i32* @SOCK_STREAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %6
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%43 = load i32, i32* @errno
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %36
%46 = call i32 @bzero(%struct.sockaddr_in* %7, i32 16)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i32, i32* %8
%50 = call i32 @htons(i32 %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %50, i32* %51
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 3
%54 = load i8*, i8** %53
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %65
56: ; preds = %45
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%61 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %60, i32 0, i32 0
%62 = load i64, i64* %61
%63 = inttoptr i64 %62 to %struct.in_addr*
%64 = call i32 @inet_aton(i8* %59, %struct.in_addr* %63)
br label %69
65: ; preds = %45
%66 = load i64, i64* @INADDR_ANY
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%68 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %67, i32 0, i32 0
store i64 %66, i64* %68
br label %69
69: ; preds = %65, %56
%70 = load i32, i32* %6
%71 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%72 = call i32 @bind(i32 %70, %struct.sockaddr* %71, i32 16)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %78
74: ; preds = %69
%75 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%76 = load i32, i32* @errno
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %69
%79 = load i32, i32* %6
%80 = load i32, i32* %9
%81 = call i64 @listen(i32 %79, i32 %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %78
%84 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%85 = load i32, i32* @errno
%86 = call i32 @exit(i32 %85)
unreachable
87: ; preds = %78
%88 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %89
89: ; preds = %87
%90 = call i32 @sleep(i32 10)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"socket failed!\00"
@errno = global i32 0
@INADDR_ANY = global i64 0
@.str.1 = [13 x i8] c"bind failed!\00"
@.str.2 = [15 x i8] c"listen failed!\00"
@str = [14 x i8] c"Listen Begin!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @atoi(i8* %10)
br label %14
14: ; preds = %8, %12
%15 = phi i32 [ %13, %12 ], [ 7878, %8 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @atoi(i8* %17)
br label %21
21: ; preds = %14, %19
%22 = phi i32 [ %20, %19 ], [ 5, %14 ]
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @errno
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %21
%32 = call i32 @bzero(%struct.sockaddr_in* %3, i32 16)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %33, i32* %34
%35 = tail call i32 @htons(i32 %15)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %35, i32* %36
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = icmp eq i8* %38, null
br i1 %39, label %45, label %40
40: ; preds = %31
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to %struct.in_addr*
%44 = tail call i32 @inet_aton(i8* %38, %struct.in_addr* %43)
br label %48
45: ; preds = %31
%46 = load i64, i64* @INADDR_ANY
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i64 %46, i64* %47
br label %48
48: ; preds = %45, %40
%49 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%50 = call i32 @bind(i32 %25, %struct.sockaddr* %49, i32 16)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%54 = load i32, i32* @errno
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %48
%57 = call i64 @listen(i32 %25, i32 %22)
%58 = icmp eq i64 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %56
%60 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%61 = load i32, i32* @errno
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %56
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%65 = call i32 @sleep(i32 10)
ret i32 0
}