#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_live;
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*/ mul_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_MULTICAST_TTL;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in mul_addr;
  int time_live = 64;
  int fd, ret, str_len;
  char buf[10];
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <ip> <port>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd == -1) {
    perror("socket() failed");
    exit(EXIT_FAILURE);
  }
  memset(&mul_addr, 0, sizeof(mul_addr));
  mul_addr.sin_family = AF_INET;
  mul_addr.sin_addr.s_addr = inet_addr(argv[1]);
  mul_addr.sin_port = htons(atoi(argv[2]));
  ret = setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &time_live,
                   sizeof(time_live));
  if (ret == -1) {
    perror("setsockopt() failed");
    exit(EXIT_FAILURE);
  }
  fd = open("news_sender.c", O_RDONLY);
  if (fd == -1) {
    perror("open() failed");
    exit(EXIT_FAILURE);
  }
  while ((str_len = read(fd, buf, sizeof(buf) - 1)) > 0) {
    buf[str_len] = '\0';
    sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&mul_addr,
           sizeof(mul_addr));
    sleep(3);
  }
  close(fd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x40,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1241 <main+0x51>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdd2(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1281 <main+0x91>
lea    0xda9(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
lea    -0x24(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    130f <main+0x11f>
lea    0xd2b(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%esi
lea    0xd1c(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    134b <main+0x15b>
lea    0xd11(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    1350 <main+0x160>
mov    -0x28(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x9,%edx
call   1090 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    13b6 <main+0x1c6>
movslq -0x30(%rbp),%rax
movb   $0x0,-0x3a(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    -0x3a(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x3a(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    $0x3,%edi
call   1100 <sleep@plt>
jmp    1350 <main+0x160>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbp
movl   $0x40,0xc(%rsp)
cmp    $0x3,%edi
jne    1340 <main+0x150>
mov    0x2dd3(%rip),%rbx
mov    (%rbx),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
je     135b <main+0x16b>
mov    %eax,%r14d
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%rbp),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
mov    0x2d3d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1364 <main+0x174>
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
lea    0xd92(%rip),%rdi
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     136d <main+0x17d>
mov    %eax,%ebp
lea    0x1e(%rsp),%rsi
mov    %eax,%edi
mov    $0x9,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1324 <main+0x134>
lea    0x1e(%rsp),%rbx
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,0x1e(%rsp,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    $0x3,%edi
call   1100 <sleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     12e0 <main+0xf0>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xcac(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    1379 <main+0x189>
lea    0xcb5(%rip),%rdi
jmp    1374 <main+0x184>
lea    0xcbc(%rip),%rdi
jmp    1374 <main+0x184>
lea    0xcd5(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s <ip> <port>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str.2 = [20 x i8] c"setsockopt() failed\00"
@.str.3 = [14 x i8] c"news_sender.c\00"
@O_RDONLY = global i32 0
@.str.4 = [14 x i8] c"open() failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 64, i32* %8
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %23
%34 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @inet_addr(i8* %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
%47 = call i32 @htons(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %47, i32* %48
%49 = load i32, i32* %6
%50 = load i32, i32* @IPPROTO_IP
%51 = load i32, i32* @IP_MULTICAST_TTL
%52 = call i32 @setsockopt(i32 %49, i32 %50, i32 %51, i32* %8, i32 4)
store i32 %52, i32* %10
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %59
55: ; preds = %33
%56 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %33
%60 = load i32, i32* @O_RDONLY
%61 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %60)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %59
%65 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %59
br label %69
69: ; preds = %74, %68
%70 = load i32, i32* %9
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%72 = call i32 @read(i32 %70, i8* %71, i32 9)
store i32 %72, i32* %11
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %85
74: ; preds = %69
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 %76
store i8 0, i8* %77
%78 = load i32, i32* %6
%79 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%80 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%81 = call i32 @strlen(i8* %80)
%82 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%83 = call i32 @sendto(i32 %78, i8* %79, i32 %81, i32 0, %struct.sockaddr* %82, i32 12)
%84 = call i32 @sleep(i32 3)
br label %69
85: ; preds = %69
%86 = load i32, i32* %9
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* %6
%89 = call i32 @close(i32 %88)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s <ip> <port>\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@IPPROTO_IP = global i32 0
@IP_MULTICAST_TTL = global i32 0
@.str.2 = [20 x i8] c"setsockopt() failed\00"
@.str.3 = [14 x i8] c"news_sender.c\00"
@O_RDONLY = global i32 0
@.str.4 = [14 x i8] c"open() failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 64, i32* %4
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @inet_addr(i8* %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %31, i32* %32
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* @IPPROTO_IP
%39 = load i32, i32* @IP_MULTICAST_TTL
%40 = call i32 @setsockopt(i32 %19, i32 %38, i32 %39, i32* %4, i32 4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %25
%43 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %25
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %55, label %50
50: ; preds = %46
%51 = call i32 @read(i32 %48, i8* %8, i32 9)
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %68
53: ; preds = %50
%54 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %59
55: ; preds = %46
%56 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %53, %59
%60 = phi i32 [ %51, %53 ], [ %66, %59 ]
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %61
store i8 0, i8* %62
%63 = call i32 @strlen(i8* %8)
%64 = call i32 @sendto(i32 %19, i8* %8, i32 %63, i32 0, %struct.sockaddr* %54, i32 12)
%65 = call i32 @sleep(i32 3)
%66 = call i32 @read(i32 %48, i8* %8, i32 9)
%67 = icmp sgt i32 %66, 0
br i1 %67, label %59, label %68
68: ; preds = %59, %50
%69 = call i32 @close(i32 %48)
%70 = call i32 @close(i32 %19)
ret i32 0
}