#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ groupSock;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int rand();
scalar_t__ sendto(int, char const *, scalar_t__, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char const *);
void udpSend(int port, const char *s) {
  int sd;
  struct sockaddr_in groupSock;
  if ((rand() % 100) > 30)
    return;
  sd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sd < 0) {
    perror("Opening datagram socket error");
    die("send failed");
  }
  memset((char *)&groupSock, 0, sizeof(groupSock));
  groupSock.sin_family = AF_INET;
  groupSock.sin_addr.s_addr = inet_addr("127.0.0.1");
  groupSock.sin_port = htons(port);
  if (sendto(sd, s, strlen(s) + 1, 0, (struct sockaddr *)&groupSock,
             sizeof(groupSock)) < 0) {
    perror("Sending datagram message error");
    die("send failed");
    return;
  }
  close(sd);
}


x86 assembly (clang, -O0):
<udpSend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x1e,%edx
jle    11cc <udpSend+0x2c>
jmp    12a5 <udpSend+0x105>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    120a <udpSend+0x6a>
lea    0xe07(%rip),%rdi
call   10a0 <perror@plt>
lea    0xe19(%rip),%rdi
call   1090 <die@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xdfd(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
cmp    $0x0,%rax
jge    129d <udpSend+0xfd>
lea    0xdad(%rip),%rdi
call   10a0 <perror@plt>
lea    0xd8b(%rip),%rdi
call   1090 <die@plt>
jmp    12a5 <udpSend+0x105>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udpSend>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x1e,%eax
jg     1260 <udpSend+0xc0>
mov    0x2e04(%rip),%r12
mov    (%r12),%edi
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     126d <udpSend+0xcd>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
lea    0xe0b(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
test   %rax,%rax
js     128a <udpSend+0xea>
mov    %ebp,%edi
call   1070 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8c(%rip),%rdi
call   10a0 <perror@plt>
lea    0xd9e(%rip),%rdi
call   1090 <die@plt>
jmp    11fe <udpSend+0x5e>
lea    0xda3(%rip),%rdi
call   10a0 <perror@plt>
lea    0xd81(%rip),%rdi
call   1090 <die@plt>
jmp    1260 <udpSend+0xc0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [30 x i8] c"Opening datagram socket error\00"
@.str.1 = [12 x i8] c"send failed\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [31 x i8] c"Sending datagram message error\00"
define void @udpSend(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 100
%9 = icmp sgt i32 %8, 30
br i1 %9, label %10, label %11
10: ; preds = %2
br label %45
11: ; preds = %2
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %11
%21 = bitcast %struct.sockaddr_in* %6 to i8*
%22 = call i32 @memset(i8* %21, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* %3
%29 = call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %5
%32 = load i8*, i8** %4
%33 = load i8*, i8** %4
%34 = call i64 @strlen(i8* %33)
%35 = add nsw i64 %34, 1
%36 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%37 = call i64 @sendto(i32 %31, i8* %32, i64 %35, i32 0, %struct.sockaddr* %36, i32 12)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %20
%40 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %45
42: ; preds = %20
%43 = load i32, i32* %5
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %42, %39, %10
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [30 x i8] c"Opening datagram socket error\00"
@.str.1 = [12 x i8] c"send failed\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [31 x i8] c"Sending datagram message error\00"
define void @udpSend(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 100
%7 = icmp sgt i32 %6, 30
br i1 %7, label %34, label %8
8: ; preds = %2
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13, %8
%17 = call i32 @memset(i8* %4, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = call i32 @htons(i32 %0)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = call i64 @strlen(i8* dereferenceable(1) %1)
%25 = add nsw i64 %24, 1
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i64 @sendto(i32 %11, i8* %1, i64 %25, i32 0, %struct.sockaddr* %26, i32 12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %16
%30 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @die(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %34
32: ; preds = %16
%33 = call i32 @close(i32 %11)
br label %34
34: ; preds = %2, %32, %29
ret void
}