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

/* Variables and functions */
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
int strlen(char *);
void cSendTo(char *msg, int socket, struct sockaddr_in *addr) {
  int msgLen = strlen(msg) + 1;
  if (addr == NULL)
    sendto(socket, msg, msgLen, 0, (struct sockaddr *)addr,
           (socklen_t)sizeof(addr));
  else
    sendto(socket, msg, msgLen, 0, NULL, 0);
}


x86 assembly (clang, -O0):
<cSendTo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116d <cSendTo+0x4d>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0x8,%r9d
call   1040 <sendto@plt>
jmp    1187 <cSendTo+0x67>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %r9d,%r9d
xor    %eax,%eax
mov    %eax,%r8d
mov    %r9d,%ecx
call   1040 <sendto@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cSendTo>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
xor    %r9d,%r9d
test   %rbx,%rbx
sete   %r9b
shl    $0x3,%r9d
mov    %r14d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
xor    %r8d,%r8d
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <sendto@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define void @cSendTo(i8* %0, i32 %1, %struct.sockaddr_in* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sockaddr_in*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store %struct.sockaddr_in* %2, %struct.sockaddr_in** %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
store i32 %10, i32* %7
%11 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%12 = icmp eq %struct.sockaddr_in* %11, null
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i8*, i8** %4
%16 = load i32, i32* %7
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%18 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%19 = call i32 @sendto(i32 %14, i8* %15, i32 %16, i32 0, %struct.sockaddr* %18, i32 8)
br label %25
20: ; preds = %3
%21 = load i32, i32* %5
%22 = load i8*, i8** %4
%23 = load i32, i32* %7
%24 = call i32 @sendto(i32 %21, i8* %22, i32 %23, i32 0, %struct.sockaddr* null, i32 0)
br label %25
25: ; preds = %20, %13
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define void @cSendTo(i8* %0, i32 %1, %struct.sockaddr_in* readnone %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = icmp eq %struct.sockaddr_in* %2, null
%7 = select i1 %6, i32 8, i32 0
%8 = tail call i32 @sendto(i32 %1, i8* %0, i32 %5, i32 0, %struct.sockaddr* null, i32 %7)
ret void
}