#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*/ socklen_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
           int /*<<< orphan*/);
int sendMessage(int sockfd, char *buf, int buflen, struct sockaddr *servaddr,
                socklen_t servlen) {
  int msg;
  if ((msg = sendto(sockfd, buf, buflen, 0, servaddr, servlen)) < 0) {
    printf("Call to sendto failed\n");
    exit(1);
  }
  printf("Message sent\n");
  return 0;
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
xor    %ecx,%ecx
call   1040 <sendto@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1185 <sendMessage+0x55>
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rax
mov    %r8d,%r9d
mov    %rcx,%r8
xor    %ecx,%ecx
call   1040 <sendto@plt>
test   %eax,%eax
js     1152 <sendMessage+0x22>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"Call to sendto failed\0A\00"
@.str.1 = [14 x i8] c"Message sent\0A\00"
define i32 @sendMessage(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.sockaddr*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store %struct.sockaddr* %3, %struct.sockaddr** %9
store i32 %4, i32* %10
%12 = load i32, i32* %6
%13 = load i8*, i8** %7
%14 = load i32, i32* %8
%15 = load %struct.sockaddr*, %struct.sockaddr** %9
%16 = load i32, i32* %10
%17 = call i32 @sendto(i32 %12, i8* %13, i32 %14, i32 0, %struct.sockaddr* %15, i32 %16)
store i32 %17, i32* %11
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %5
%23 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@str = [13 x i8] c"Message sent\00"
@str.2 = [22 x i8] c"Call to sendto failed\00"
define i32 @sendMessage(i32 %0, i8* %1, i32 %2, %struct.sockaddr* %3, i32 %4) {
%6 = tail call i32 @sendto(i32 %0, i8* %1, i32 %2, i32 0, %struct.sockaddr* %3, i32 %4)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret i32 0
}