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

/* Variables and functions */
int parse(char *, struct sockaddr_in *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int udp_send(int udpsocket, char *msg, int msglen, char *announce) {
  struct sockaddr_in sa;
  int err;
  err = parse(announce, &sa);
  if (err) {
    printf("Error parsing url '%s'\n", announce);
    return err;
  }
  err = sendto(udpsocket, msg, msglen, 0, (struct sockaddr *)&sa, sizeof(sa));
  if (err == -1) {
    perror("send error");
    return -3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<udp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <parse@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     118b <udp_send+0x4b>
mov    -0x20(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <udp_send+0x92>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1040 <sendto@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11cb <udp_send+0x8b>
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11d2 <udp_send+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udp_send>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%r12d
lea    0x8(%rsp),%rsi
mov    %rcx,%rdi
call   1060 <parse@plt>
test   %eax,%eax
je     117c <udp_send+0x3c>
mov    %eax,%ebx
lea    0xe8e(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
jmp    119e <udp_send+0x5e>
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1040 <sendto@plt>
cmp    $0xffffffff,%eax
je     11ad <udp_send+0x6d>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    $0xfffffffd,%ebx
jmp    119e <udp_send+0x5e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Error parsing url '%s'\0A\00"
@.str.1 = [11 x i8] c"send error\00"
define i32 @udp_send(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%12 = load i8*, i8** %9
%13 = call i32 @parse(i8* %12, %struct.sockaddr_in* %10)
store i32 %13, i32* %11
%14 = load i32, i32* %11
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i8*, i8** %9
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %11
store i32 %19, i32* %5
br label %31
20: ; preds = %4
%21 = load i32, i32* %6
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%25 = call i32 @sendto(i32 %21, i8* %22, i32 %23, i32 0, %struct.sockaddr* %24, i32 4)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 -3, i32* %5
br label %31
30: ; preds = %20
store i32 0, i32* %5
br label %31
31: ; preds = %30, %28, %16
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [24 x i8] c"Error parsing url '%s'\0A\00"
@.str.1 = [11 x i8] c"send error\00"
define i32 @udp_send(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca %struct.sockaddr_in
%6 = bitcast %struct.sockaddr_in* %5 to i8*
%7 = call i32 @parse(i8* %3, %struct.sockaddr_in* %5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %17
11: ; preds = %4
%12 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%13 = call i32 @sendto(i32 %0, i8* %1, i32 %2, i32 0, %struct.sockaddr* %12, i32 4)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %11, %15, %9
%18 = phi i32 [ %7, %9 ], [ -3, %15 ], [ 0, %11 ]
ret i32 %18
}