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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  assert(sd > 0);
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
  addr.sin_port = htons(53);
  char *request = "hi, i like you";
  int ret = sendto(sd, request, strlen(request), 0, (struct sockaddr *)&addr,
                   sizeof(addr));
  assert(ret >= 0);
  close(sd);
  return EXIT_SUCCESS;
}


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    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    0xe02(%rip),%rsi
call   1090 <inet_pton@plt>
mov    $0x35,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    0xdf3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1080 <assert@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
lea    0x4(%rsp),%rdx
lea    0xe1e(%rip),%rsi
call   1090 <inet_pton@plt>
mov    $0x35,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
lea    0xe0f(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [15 x i8] c"hi, i like you\00"
@EXIT_SUCCESS = 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 i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = load i32, i32* @IPPROTO_UDP
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%23 = call i32 @inet_pton(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %22)
%24 = call i32 @htons(i32 53)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %24, i32* %25
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %8
%26 = load i32, i32* %6
%27 = load i8*, i8** %8
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i32 @sendto(i32 %26, i8* %27, i32 %29, i32 0, %struct.sockaddr* %30, i32 12)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp sge i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* @EXIT_SUCCESS
ret i32 %38
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [15 x i8] c"hi, i like you\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = load i32, i32* @PF_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 sgt i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%16 = call i32 @inet_pton(i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %15)
%17 = call i32 @htons(i32 53)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @sendto(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 0, %struct.sockaddr* %20, i32 12)
%22 = xor i32 %21, -1
%23 = lshr i32 %22, 31
%24 = call i32 @assert(i32 %23)
%25 = call i32 @close(i32 %7)
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}