#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 tftp_msg {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ msg_with_correct_len(struct tftp_msg *, size_t);
int /*<<< orphan*/ perror(char *);
int send(int, char *, size_t, int /*<<< orphan*/);
int tftp_msg_send(struct tftp_msg *msg, size_t msg_len, int sock) {
  assert(msg_with_correct_len(msg, msg_len));
  if (-1 == send(sock, (char *)msg, msg_len, 0)) {
    perror("tftp: send() failure");
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<tftp_msg_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <msg_with_correct_len@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a7 <tftp_msg_send+0x67>
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
mov    0x2e43(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <tftp_msg_send+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tftp_msg_send>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1040 <msg_with_correct_len@plt>
mov    %eax,%edi
call   1050 <assert@plt>
xor    %r15d,%r15d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
call   1030 <send@plt>
cmp    $0xffffffff,%eax
je     1182 <tftp_msg_send+0x42>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4b(%rip),%rax
xor    %r15d,%r15d
sub    (%rax),%r15d
jmp    1174 <tftp_msg_send+0x34>

LLVM IR (-O0):
%struct.tftp_msg = type { i32 }
@.str = [21 x i8] c"tftp: send() failure\00"
@errno = global i32 0
define i32 @tftp_msg_send(%struct.tftp_msg* %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.tftp_msg*
%6 = alloca i64
%7 = alloca i32
store %struct.tftp_msg* %0, %struct.tftp_msg** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%8 = load %struct.tftp_msg*, %struct.tftp_msg** %5
%9 = load i64, i64* %6
%10 = call i32 @msg_with_correct_len(%struct.tftp_msg* %8, i64 %9)
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %7
%13 = load %struct.tftp_msg*, %struct.tftp_msg** %5
%14 = bitcast %struct.tftp_msg* %13 to i8*
%15 = load i64, i64* %6
%16 = call i32 @send(i32 %12, i8* %14, i64 %15, i32 0)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %22
18: ; preds = %3
%19 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @errno
%21 = sub nsw i32 0, %20
store i32 %21, i32* %4
br label %23
22: ; preds = %3
store i32 0, i32* %4
br label %23
23: ; preds = %22, %18
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
%struct.tftp_msg = type { i32 }
@.str = [21 x i8] c"tftp: send() failure\00"
@errno = global i32 0
define i32 @tftp_msg_send(%struct.tftp_msg* %0, i64 %1, i32 %2) {
%4 = tail call i32 @msg_with_correct_len(%struct.tftp_msg* %0, i64 %1)
%5 = tail call i32 @assert(i32 %4)
%6 = bitcast %struct.tftp_msg* %0 to i8*
%7 = tail call i32 @send(i32 %2, i8* %6, i64 %1, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @errno
%12 = sub nsw i32 0, %11
br label %13
13: ; preds = %3, %9
%14 = phi i32 [ %12, %9 ], [ 0, %3 ]
ret i32 %14
}