#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 */
typedef int /*<<< orphan*/ time_t;
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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ sender;
typedef int /*<<< orphan*/ on;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ sendto(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *,
                  int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sockfd, on = 1;
  struct sockaddr_in sender;
  int sender_len = sizeof(sender);
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    perror("socket failed");
    exit(EXIT_FAILURE);
  }
  memset(&sender, 0, sizeof(sender));
  sender.sin_family = AF_INET;
  sender.sin_addr.s_addr = inet_addr("226.0.0.3");
  sender.sin_port = htons(12345);
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, (socklen_t)sizeof(on));
  for (;;) {
    char msg[80];
    time_t t = time(0);
    sprintf(msg, "time is %-24.24s", ctime(&t));
    printf("sending msg = %s\n", msg);
    size_t msg_len = strlen(msg) + 1;
    ssize_t n =
        sendto(sockfd, msg, msg_len, 0, (struct sockaddr *)&sender, sender_len);
    if (n < 0)
      perror("sendto error");
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1247 <main+0x67>
lea    0xdcc(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xda4(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x3039,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x84(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0xa0(%rbp),%rdi
mov    %rax,%rdx
lea    0xd40(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x80(%rbp),%rsi
lea    0xd41(%rip),%rdi
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x90(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x90(%rbp),%rdx
lea    -0x28(%rbp),%r8
mov    -0x2c(%rbp),%r9d
xor    %ecx,%ecx
call   1090 <sendto@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jge    1340 <main+0x160>
lea    0xd00(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10f0 <sleep@plt>
jmp    12a3 <main+0xc3>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2de3(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12fc <main+0x11c>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0xdd4(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x3039,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    0x2d5f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0x8(%rsp),%r15
lea    0xd97(%rip),%r12
lea    0x20(%rsp),%rbx
lea    0xd9c(%rip),%r13
jmp    129a <main+0xba>
nop
mov    $0x1,%edi
call   10f0 <sleep@plt>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,0x8(%rsp)
mov    %r15,%rdi
call   1040 <ctime@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   10d0 <sprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1090 <sendto@plt>
test   %rax,%rax
jns    1290 <main+0xb0>
lea    0xd46(%rip),%rdi
call   10c0 <perror@plt>
jmp    1290 <main+0xb0>
lea    0xcfd(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

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 = [14 x i8] c"socket failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"226.0.0.3\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [17 x i8] c"time is %-24.24s\00"
@.str.3 = [18 x i8] c"sending msg = %s\0A\00"
@.str.4 = [13 x i8] c"sendto error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [80 x i8]
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 12, i32* %9
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = call i32 @htons(i32 12345)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* %6
%33 = load i32, i32* @SOL_SOCKET
%34 = load i32, i32* @SO_REUSEADDR
%35 = call i32 @setsockopt(i32 %32, i32 %33, i32 %34, i32* %7, i32 4)
br label %36
36: ; preds = %57, %23
%37 = call i32 @time(i32 0)
store i32 %37, i32* %11
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%39 = call i8* @ctime(i32* %11)
%40 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = add nsw i32 %44, 1
%46 = sext i32 %45 to i64
store i64 %46, i64* %12
%47 = load i32, i32* %6
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%49 = load i64, i64* %12
%50 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%51 = load i32, i32* %9
%52 = call i64 @sendto(i32 %47, i8* %48, i64 %49, i32 0, %struct.sockaddr* %50, i32 %51)
store i64 %52, i64* %13
%53 = load i64, i64* %13
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %36
%56 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %55, %36
%58 = call i32 @sleep(i32 1)
br label %36
}

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 = [14 x i8] c"socket failed\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"226.0.0.3\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [17 x i8] c"time is %-24.24s\00"
@.str.3 = [18 x i8] c"sending msg = %s\0A\00"
@.str.4 = [13 x i8] c"sendto error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%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 %17
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = call i32 @htons(i32 12345)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = call i32 @setsockopt(i32 %11, i32 %25, i32 %26, i32* %3, i32 4)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%29 = bitcast i32* %6 to i8*
%30 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %31
31: ; preds = %43, %17
%32 = call i32 @time(i32 0)
store i32 %32, i32* %6
%33 = call i8* @ctime(i32* %6)
%34 = call i32 @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%36 = call i32 @strlen(i8* %28)
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = call i64 @sendto(i32 %11, i8* %28, i64 %38, i32 0, %struct.sockaddr* %30, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %31
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %31
%44 = call i32 @sleep(i32 1)
br label %31
}