#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;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dg_cli(int /*<<< orphan*/, int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
main() {
  int sockfd, i = 0;
  struct sockaddr_in cli_addr, serv_addr;
  char arg[512];
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  serv_addr.sin_port = htons(9000);
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
    perror("client: can't open datagram socket");
  bzero((char *)&cli_addr, sizeof(cli_addr));
  cli_addr.sin_family = AF_INET;
  cli_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  cli_addr.sin_port = htons(0);
  if (bind(sockfd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)) < 0)
    perror("client: can't bind local address");
  dg_cli(stdin, sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
lea    0xe24(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x38(%rbp)
mov    $0x2328,%edi
call   1030 <htons@plt>
mov    %rax,-0x40(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%rdi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1224 <main+0x84>
lea    0xdeb(%rip),%rdi
call   1080 <perror@plt>
lea    -0x28(%rbp),%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x20(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x18,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1283 <main+0xe3>
lea    0xdaf(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
lea    -0x40(%rbp),%rdx
mov    $0x18,%ecx
call   10a0 <dg_cli@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsp,%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    0x2e2b(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
lea    0xe34(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    $0x2328,%edi
call   1030 <htons@plt>
mov    %rax,(%rsp)
mov    (%r15),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1208 <main+0x68>
lea    0xe07(%rip),%rdi
call   1080 <perror@plt>
lea    0x18(%rsp),%r14
mov    %r14,%rdi
mov    $0x18,%esi
call   1090 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x28(%rsp)
mov    0x2daf(%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   1070 <bind@plt>
test   %rax,%rax
jns    1260 <main+0xc0>
lea    0xdd2(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
mov    %ebx,%esi
mov    $0x18,%ecx
call   10a0 <dg_cli@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@.str.1 = [35 x i8] c"client: can't open datagram socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [33 x i8] c"client: can't bind local address\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [512 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = call i32 @bzero(i8* %7, i32 24)
%9 = load i8*, i8** @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i8* %9, i8** %10
%11 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = call i8* @htons(i32 9000)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i8* %14, i8** %15
%16 = load i8*, i8** @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = call i32 @socket(i8* %16, i32 %17, i32 0)
store i32 %18, i32* %2
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %0
%23 = bitcast %struct.sockaddr_in* %4 to i8*
%24 = call i32 @bzero(i8* %23, i32 24)
%25 = load i8*, i8** @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i8* %25, i8** %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = call i8* @htons(i32 0)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i8* %31, i8** %32
%33 = load i32, i32* %2
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i64 @bind(i32 %33, %struct.sockaddr* %34, i32 24)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %22
%38 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %22
%40 = load i32, i32* @stdin
%41 = load i32, i32* %2
%42 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%43 = call i32 @dg_cli(i32 %40, i32 %41, %struct.sockaddr* %42, i32 24)
%44 = load i32, i32* %2
%45 = call i32 @close(i32 %44)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i8* null
@.str = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@.str.1 = [35 x i8] c"client: can't open datagram socket\00"
@INADDR_ANY = global i32 0
@.str.2 = [33 x i8] c"client: can't bind local address\00"
@stdin = global i32 0
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 = call i32 @bzero(i8* %4, i32 24)
%6 = load i8*, i8** @AF_INET
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %6, i8** %7
%8 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %8, i32* %9
%10 = tail call i8* @htons(i32 9000)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i8* %10, i8** %11
%12 = load i8*, i8** @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = tail call i32 @socket(i8* %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
%19 = call i32 @bzero(i8* %3, i32 24)
%20 = load i8*, i8** @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %20, i8** %21
%22 = load i32, i32* @INADDR_ANY
%23 = tail call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = tail call i8* @htons(i32 0)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %25, i8** %26
%27 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%28 = call i64 @bind(i32 %14, %struct.sockaddr* %27, i32 24)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %18
%33 = load i32, i32* @stdin
%34 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%35 = call i32 @dg_cli(i32 %33, i32 %14, %struct.sockaddr* %34, i32 24)
%36 = call i32 @close(i32 %14)
%37 = call i32 @exit(i32 0)
unreachable
}