#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 {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ real_sendto(int, void const *, size_t, int,
                               struct sockaddr const *, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, void const *, size_t, int);
ssize_t sendto(int fd, const void *buffer, size_t length, int flags,
               const struct sockaddr *dest_addr, socklen_t addrlen) {
  if (dest_addr == NULL) {
    return send(fd, buffer, length, flags);
  } else {
    return real_sendto(fd, buffer, length, flags, dest_addr, addrlen);
  }
}


x86 assembly (clang, -O0):
<sendto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1164 <sendto+0x44>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <send@plt>
mov    %eax,-0x4(%rbp)
jmp    1182 <sendto+0x62>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
call   1030 <real_sendto@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendto>:
test   %r8,%r8
je     112a <sendto+0xa>
jmp    1030 <real_sendto@plt>
jmp    1040 <send@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
define i32 @sendto(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.sockaddr*
%13 = alloca i32
store i32 %0, i32* %8
store i8* %1, i8** %9
store i64 %2, i64* %10
store i32 %3, i32* %11
store %struct.sockaddr* %4, %struct.sockaddr** %12
store i32 %5, i32* %13
%14 = load %struct.sockaddr*, %struct.sockaddr** %12
%15 = icmp eq %struct.sockaddr* %14, null
br i1 %15, label %16, label %22
16: ; preds = %6
%17 = load i32, i32* %8
%18 = load i8*, i8** %9
%19 = load i64, i64* %10
%20 = load i32, i32* %11
%21 = call i32 @send(i32 %17, i8* %18, i64 %19, i32 %20)
store i32 %21, i32* %7
br label %30
22: ; preds = %6
%23 = load i32, i32* %8
%24 = load i8*, i8** %9
%25 = load i64, i64* %10
%26 = load i32, i32* %11
%27 = load %struct.sockaddr*, %struct.sockaddr** %12
%28 = load i32, i32* %13
%29 = call i32 @real_sendto(i32 %23, i8* %24, i64 %25, i32 %26, %struct.sockaddr* %27, i32 %28)
store i32 %29, i32* %7
br label %30
30: ; preds = %22, %16
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @sendto(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5) {
%7 = icmp eq %struct.sockaddr* %4, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 @send(i32 %0, i8* %1, i64 %2, i32 %3)
br label %12
10: ; preds = %6
%11 = tail call i32 @real_sendto(i32 %0, i8* %1, i64 %2, i32 %3, %struct.sockaddr* %4, i32 %5)
br label %12
12: ; preds = %10, %8
%13 = phi i32 [ %9, %8 ], [ %11, %10 ]
ret i32 %13
}