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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
main(int argc, char *argv[]) {
  struct sockaddr_in addr;
  int fd, cnt;
  struct ip_mreq mreq;
  char *msgbuf = "hello";
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr("225.0.0.37");
  addr.sin_port = htons(12345);
  while (1) {
    if (sendto(fd, msgbuf, sizeof(msgbuf), 0, (struct sockaddr *)&addr,
               sizeof(addr)) < 0) {
      perror("sendto");
      exit(1);
    }
    fprintf(stdout, "%d, %s\n", sizeof(msgbuf), msgbuf);
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11ec <main+0x5c>
lea    0xe29(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xdfe(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x3039,%edi
call   1030 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x38(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x8,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
cmp    $0x0,%rax
jge    1261 <main+0xd1>
lea    0xdc6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rcx
lea    0xdaa(%rip),%rsi
mov    $0x8,%edx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1224 <main+0x94>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e45(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
jns    11c5 <main+0x35>
lea    0xe46(%rip),%rdi
jmp    1284 <main+0xf4>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe27(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x3039,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
lea    0xdfd(%rip),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
js     127d <main+0xed>
mov    0x2daa(%rip),%r12
lea    0xdf2(%rip),%r14
lea    0xdcc(%rip),%rbx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %r14,%rsi
mov    $0x8,%edx
mov    %rbx,%rcx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
jns    1240 <main+0xb0>
lea    0xd94(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.ip_mreq = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"hello\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [11 x i8] c"225.0.0.37\00"
@.str.3 = [7 x i8] c"sendto\00"
@stdout = global i32 0
@.str.4 = [8 x i8] c"%d, %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.ip_mreq
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = call i32 @htons(i32 12345)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %25, i32* %26
br label %27
27: ; preds = %18, %36
%28 = load i32, i32* %7
%29 = load i8*, i8** %10
%30 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%31 = call i64 @sendto(i32 %28, i8* %29, i32 8, i32 0, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i32, i32* @stdout
%38 = load i8*, i8** %10
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 8, i8* %38)
%40 = call i32 @sleep(i32 1)
br label %27
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [6 x i8] c"hello\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [11 x i8] c"225.0.0.37\00"
@.str.3 = [7 x i8] c"sendto\00"
@stdout = global i32 0
@.str.4 = [8 x i8] c"%d, %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = call i32 @htons(i32 12345)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @sendto(i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 8, i32 0, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %26, %12
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12, %26
%27 = load i32, i32* @stdout
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @sleep(i32 1)
%30 = call i64 @sendto(i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 8, i32 0, %struct.sockaddr* %20, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %23, label %26
}