#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 stat {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ in_port_t;
typedef int /*<<< orphan*/ in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
size_t sendto(int, void *, size_t, int /*<<< orphan*/, struct sockaddr const *,
              int);
int /*<<< orphan*/ stderr;
int udt_send(int udt, in_addr_t addr, in_port_t port, void *buff,
             size_t nbytes) {
  struct stat info;
  if (fstat(udt, &info) != 0) {
    fprintf(stderr,
            "UDT: descriptor is invalid, probably udt_init not called.\n");
    exit(EXIT_FAILURE);
  }
  struct sockaddr_in sa;
  bzero(&sa, sizeof(sa));
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = htonl(addr);
  sa.sin_port = htons(port);
  ssize_t nsend =
      sendto(udt, buff, nbytes, 0, (const struct sockaddr *)&sa, sizeof(sa));
  return nsend == nbytes;
}


x86 assembly (clang, -O0):
<udt_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1090 <fstat@plt>
cmp    $0x0,%rax
je     11c2 <udt_send+0x52>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    -0x38(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x20(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udt_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r12
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x10(%rsp),%rsi
call   1090 <fstat@plt>
test   %rax,%rax
jne    11fe <udt_send+0x8e>
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1040 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
xor    %ecx,%ecx
cmp    %r12,%rax
sete   %cl
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [59 x i8] c"UDT: descriptor is invalid, probably udt_init not called.\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
define i32 @udt_send(i32 %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.stat
%12 = alloca %struct.sockaddr_in
%13 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%14 = load i32, i32* %6
%15 = call i64 @fstat(i32 %14, %struct.stat* %11)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %5
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %5
%23 = call i32 @bzero(%struct.sockaddr_in* %12, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %7
%27 = call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %8
%31 = call i32 @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %6
%34 = load i8*, i8** %9
%35 = load i64, i64* %10
%36 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%37 = call i64 @sendto(i32 %33, i8* %34, i64 %35, i32 0, %struct.sockaddr* %36, i32 12)
store i64 %37, i64* %13
%38 = load i64, i64* %13
%39 = load i64, i64* %10
%40 = icmp eq i64 %38, %39
%41 = zext i1 %40 to i32
ret i32 %41
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [59 x i8] c"UDT: descriptor is invalid, probably udt_init not called.\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
define i32 @udt_send(i32 %0, i32 %1, i32 %2, i8* %3, i64 %4) {
%6 = alloca %struct.stat
%7 = alloca %struct.sockaddr_in
%8 = bitcast %struct.stat* %6 to i8*
%9 = call i64 @fstat(i32 %0, %struct.stat* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %5
%17 = bitcast %struct.sockaddr_in* %7 to i8*
%18 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @htonl(i32 %1)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 %2)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%26 = call i64 @sendto(i32 %0, i8* %3, i64 %4, i32 0, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i64 %26, %4
%28 = zext i1 %27 to i32
ret i32 %28
}