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

/* Variables and functions */
int sendto(int, void const *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sockaddrnumfill(struct sockaddr_in *, int /*<<< orphan*/,
                                   int);
int udpwrite(int sock, uint32_t ip, uint16_t port, const void *buff,
             uint16_t leng) {
  struct sockaddr_in sa;
  if (leng > 512) {
    return -1;
  }
  sockaddrnumfill(&sa, ip, port);
  return sendto(sock, buff, leng, 0, (struct sockaddr *)&sa,
                sizeof(struct sockaddr_in));
}


x86 assembly (clang, -O0):
<udpwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jle    1152 <udpwrite+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <udpwrite+0x5f>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x20(%rbp),%rdi
call   1040 <sockaddrnumfill@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1030 <sendto@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpwrite>:
mov    $0xffffffff,%eax
cmp    $0x200,%r8d
jg     1169 <udpwrite+0x49>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %edi,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
call   1040 <sockaddrnumfill@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1030 <sendto@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @udpwrite(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca %struct.sockaddr_in
%7 = bitcast %struct.sockaddr_in* %6 to i8*
%8 = icmp sgt i32 %4, 512
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = call i32 @sockaddrnumfill(%struct.sockaddr_in* %6, i32 %1, i32 %2)
%11 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%12 = call i32 @sendto(i32 %0, i8* %3, i32 %4, i32 0, %struct.sockaddr* %11, i32 4)
br label %13
13: ; preds = %5, %9
%14 = phi i32 [ %12, %9 ], [ -1, %5 ]
ret i32 %14
}