#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ sendto(int, char const *, scalar_t__, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
int udp_send(const char *sendbuf) {
  int fd;
  struct sockaddr_in server;
  struct hostent *he;
  socklen_t len;
  if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
    printf("%s", "Function socket() error.\n");
    return EXIT_FAILURE;
  }
  bzero(&server, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_port = htons(11600);
  if ((he = gethostbyname("127.0.0.1")) == NULL) {
    printf("%s", "Function gethostbyname() error.\n");
    close(fd);
    return EXIT_FAILURE;
  }
  server.sin_addr = *((struct in_addr *)he->h_addr);
  len = sizeof(struct sockaddr_in);
  if (sendto(fd, sendbuf, strlen(sendbuf), 0, (struct sockaddr *)&server,
             len) != strlen(sendbuf)) {
    printf("%s", "Funtcion sendto() error.\n");
    close(fd);
    return EXIT_FAILURE;
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11dc <udp_send+0x5c>
lea    0xe41(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1050 <printf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e9 <udp_send+0x169>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2d50,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe13(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1249 <udp_send+0xc9>
lea    0xddc(%rip),%rdi
lea    0xdfc(%rip),%rsi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e9 <udp_send+0x169>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
lea    -0x20(%rbp),%r8
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     12d5 <udp_send+0x155>
lea    0xd50(%rip),%rdi
lea    0xd91(%rip),%rsi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e9 <udp_send+0x169>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_send>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e55(%rip),%r15
mov    (%r15),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     122f <udp_send+0xaf>
mov    %eax,%ebx
mov    %rsp,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    $0x2d50,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe40(%rip),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     1244 <udp_send+0xc4>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rsp,%r8
mov    %ebx,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r15
jne    1254 <udp_send+0xd4>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2d9b(%rip),%rax
jmp    1275 <udp_send+0xf5>
lea    0xdca(%rip),%rdi
lea    0xdc6(%rip),%rsi
call   1050 <printf@plt>
jmp    126e <udp_send+0xee>
lea    0xdb5(%rip),%rdi
lea    0xdd5(%rip),%rsi
jmp    1262 <udp_send+0xe2>
lea    0xda5(%rip),%rdi
lea    0xde6(%rip),%rsi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [26 x i8] c"Function socket() error.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [33 x i8] c"Function gethostbyname() error.\0A\00"
@.str.4 = [26 x i8] c"Funtcion sendto() error.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @udp_send(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.hostent*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @IPPROTO_UDP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %2
br label %56
16: ; preds = %1
%17 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 11600)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %20, i32* %21
%22 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %22, %struct.hostent** %6
%23 = icmp eq %struct.hostent* %22, null
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %2
br label %56
29: ; preds = %16
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%31 = load %struct.hostent*, %struct.hostent** %6
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.in_addr*
%35 = bitcast %struct.in_addr* %30 to i8*
%36 = bitcast %struct.in_addr* %34 to i8*
store i32 12, i32* %7
%37 = load i32, i32* %4
%38 = load i8*, i8** %3
%39 = load i8*, i8** %3
%40 = call i64 @strlen(i8* %39)
%41 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%42 = load i32, i32* %7
%43 = call i64 @sendto(i32 %37, i8* %38, i64 %40, i32 0, %struct.sockaddr* %41, i32 %42)
%44 = load i8*, i8** %3
%45 = call i64 @strlen(i8* %44)
%46 = icmp ne i64 %43, %45
br i1 %46, label %47, label %52
47: ; preds = %29
%48 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %4
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* @EXIT_FAILURE
store i32 %51, i32* %2
br label %56
52: ; preds = %29
%53 = load i32, i32* %4
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* @EXIT_SUCCESS
store i32 %55, i32* %2
br label %56
56: ; preds = %52, %47, %24, %13
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [26 x i8] c"Function socket() error.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [33 x i8] c"Function gethostbyname() error.\0A\00"
@.str.4 = [26 x i8] c"Funtcion sendto() error.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @udp_send(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = load i32, i32* @IPPROTO_UDP
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %38
11: ; preds = %1
%12 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 11600)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %15, i32* %16
%17 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @close(i32 %7)
br label %38
22: ; preds = %11
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 0
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to i32*
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
%27 = load i32, i32* %25
store i32 %27, i32* %26
%28 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i64 @sendto(i32 %7, i8* %0, i64 %28, i32 0, %struct.sockaddr* %29, i32 12)
%31 = call i64 @strlen(i8* dereferenceable(1) %0)
%32 = icmp eq i64 %30, %31
br i1 %32, label %36, label %33
33: ; preds = %22
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @close(i32 %7)
br label %38
36: ; preds = %22
%37 = call i32 @close(i32 %7)
br label %38
38: ; preds = %36, %33, %19, %9
%39 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %33 ], [ @EXIT_SUCCESS, %36 ]
%40 = load i32, i32* %39
ret i32 %40
}