#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ stderr;
int udp_send(int *sock, struct sockaddr_in6 *sock_addr, char *data,
             int length) {
  int addrlen;
  addrlen = sizeof(struct sockaddr_in6);
  if (sendto(*sock, data, length, 0, (struct sockaddr *)sock_addr, addrlen) !=
      length) {
    char str_ip[128];
    inet_ntop(AF_INET6, &(sock_addr->sin6_addr), (char *)&str_ip, 128);
    fprintf(stderr, "[Error] Unable to write to UDP socket [%s]:%d\n", str_ip,
            53);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%r8
mov    -0x28(%rbp),%r9d
xor    %ecx,%ecx
call   1040 <sendto@plt>
cmp    -0x24(%rbp),%eax
je     11c1 <udp_send+0x91>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    -0xb0(%rbp),%rdx
lea    0xe55(%rip),%rsi
mov    $0x35,%ecx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <udp_send+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %ecx,%ebx
mov    %rsi,%r14
mov    (%rdi),%edi
xor    %ebp,%ebp
mov    %rdx,%rsi
mov    %ecx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x4,%r9d
call   1040 <sendto@plt>
cmp    %ebx,%eax
je     119b <udp_send+0x6b>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rbx
mov    %r14,%rsi
mov    %rbx,%rdx
mov    $0x80,%ecx
call   1030 <inet_ntop@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    %rbx,%rdx
mov    $0x35,%ecx
call   1050 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"[Error] Unable to write to UDP socket [%s]:%d\0A\00"
define i32 @udp_send(i32* %0, %struct.sockaddr_in6* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.sockaddr_in6*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [128 x i8]
store i32* %0, i32** %6
store %struct.sockaddr_in6* %1, %struct.sockaddr_in6** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 4, i32* %10
%12 = load i32*, i32** %6
%13 = load i32, i32* %12
%14 = load i8*, i8** %8
%15 = load i32, i32* %9
%16 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%17 = bitcast %struct.sockaddr_in6* %16 to %struct.sockaddr*
%18 = load i32, i32* %10
%19 = call i32 @sendto(i32 %13, i8* %14, i32 %15, i32 0, %struct.sockaddr* %17, i32 %18)
%20 = load i32, i32* %9
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %4
%23 = load i32, i32* @AF_INET6
%24 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%25 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %24, i32 0, i32 0
%26 = bitcast [128 x i8]* %11 to i8*
%27 = call i32 @inet_ntop(i32 %23, i32* %25, i8* %26, i32 128)
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %29, i32 53)
store i32 1, i32* %5
br label %32
31: ; preds = %4
store i32 0, i32* %5
br label %32
32: ; preds = %31, %22
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET6 = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"[Error] Unable to write to UDP socket [%s]:%d\0A\00"
define i32 @udp_send(i32* nocapture %0, %struct.sockaddr_in6* %1, i8* %2, i32 %3) {
%5 = alloca [128 x i8]
%6 = load i32, i32* %0
%7 = bitcast %struct.sockaddr_in6* %1 to %struct.sockaddr*
%8 = tail call i32 @sendto(i32 %6, i8* %2, i32 %3, i32 0, %struct.sockaddr* %7, i32 4)
%9 = icmp eq i32 %8, %3
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* @AF_INET6
%13 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %1, i64 0, i32 0
%14 = call i32 @inet_ntop(i32 %12, i32* %13, i8* %11, i32 128)
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %11, i32 53)
br label %17
17: ; preds = %4, %10
%18 = phi i32 [ 1, %10 ], [ 0, %4 ]
ret i32 %18
}