#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 */
typedef int /*<<< orphan*/ svaddr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ str_echo(int, struct sockaddr *, int);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in svaddr, cliaddr;
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd == -1) {
    fprintf(stderr, "socket() failed: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  memset(&svaddr, 0, sizeof(svaddr));
  svaddr.sin_family = AF_INET;
  svaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  svaddr.sin_port = htons(10000);
  bind(sockfd, (struct sockaddr *)&svaddr, sizeof(svaddr));
  str_echo(sockfd, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
  return 0;
}


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    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1206 <main+0x76>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe0d(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x2710,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1030 <str_echo@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e48(%rip),%r15
mov    (%r15),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     121e <main+0x8e>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x2710,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1030 <str_echo@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2da3(%rip),%rax
mov    (%rax),%ebx
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdc4(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"socket() failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@INADDR_ANY = 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.sockaddr_in
%8 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = call i32 @htons(i32 10000)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%33 = call i32 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = load i32, i32* %6
%35 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%36 = call i32 @str_echo(i32 %34, %struct.sockaddr* %35, i32 12)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"socket() failed: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = call i32 @htons(i32 10000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @bind(i32 %9, %struct.sockaddr* %27, i32 12)
%29 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%30 = call i32 @str_echo(i32 %9, %struct.sockaddr* %29, i32 12)
ret i32 0
}