#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 {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ my_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int net_bind(int, struct sockaddr_in *, int);
int net_open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
main() {
  int fd;
  struct sockaddr_in my_addr;
  struct sockaddr_in serv_addr;
  char buf[128];
  void echo_driver(int, struct sockaddr_in *);
  if ((fd = net_open("/dev/udp", O_RDWR)) < 0) {
    fprintf(stderr, "open failed.\n");
    exit(-1);
  }
  bzero((char *)&my_addr, sizeof(my_addr));
  my_addr.sin_family = AF_INET;
  my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  my_addr.sin_port = htons(0);
  fd = net_bind(fd, &my_addr, sizeof(struct sockaddr_in));
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr("128.220.101.4");
  serv_addr.sin_port = htons(6000);
  echo_driver(fd, &serv_addr);
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1080 <net_open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11f2 <main+0x52>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0x18,%esi
call   10b0 <bzero@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x18(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x18,%edx
call   10a0 <net_bind@plt>
mov    %eax,-0x8(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x18,%esi
call   10b0 <bzero@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
lea    0xdb6(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x30(%rbp)
mov    $0x1770,%edi
call   1030 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1090 <echo_driver@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   1080 <net_open@plt>
test   %eax,%eax
jns    11e1 <main+0x41>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    %eax,%ebx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   10b0 <bzero@plt>
mov    0x2de4(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x28(%rsp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x20(%rsp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,0x18(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x18,%edx
call   10a0 <net_bind@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   10b0 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
lea    0xdc5(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    $0x1770,%edi
call   1030 <htons@plt>
mov    %rax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
call   1090 <echo_driver@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
@.str = [9 x i8] c"/dev/udp\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"open failed.\0A\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@.str.2 = [14 x i8] c"128.220.101.4\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [128 x i8]
store i32 0, i32* %1
%6 = load i32, i32* @O_RDWR
%7 = call i32 @net_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = call i32 @bzero(i8* %14, i32 24)
%16 = load i8*, i8** @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %16, i8** %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i8* @htons(i32 0)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i8* %22, i8** %23
%24 = load i32, i32* %2
%25 = call i32 @net_bind(i32 %24, %struct.sockaddr_in* %3, i32 24)
store i32 %25, i32* %2
%26 = bitcast %struct.sockaddr_in* %4 to i8*
%27 = call i32 @bzero(i8* %26, i32 24)
%28 = load i8*, i8** @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i8* %28, i8** %29
%30 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = call i8* @htons(i32 6000)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i8* %33, i8** %34
%35 = load i32, i32* %2
%36 = load i32, i32* %2
%37 = call i32 @close(i32 %36)
%38 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
@.str = [9 x i8] c"/dev/udp\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"open failed.\0A\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@.str.2 = [14 x i8] c"128.220.101.4\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @net_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i32 @bzero(i8* %3, i32 24)
%14 = load i8*, i8** @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %14, i8** %15
%16 = load i32, i32* @INADDR_ANY
%17 = tail call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = tail call i8* @htons(i32 0)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %19, i8** %20
%21 = call i32 @net_bind(i32 %6, %struct.sockaddr_in* %1, i32 24)
%22 = call i32 @bzero(i8* %4, i32 24)
%23 = load i8*, i8** @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %23, i8** %24
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = call i8* @htons(i32 6000)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i8* %27, i8** %28
%29 = call i32 @close(i32 %21)
%30 = call i32 @exit(i32 0)
unreachable
}