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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
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 /*<<< orphan*/ printf(char *, 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 broad_addr;
  int opt = 1;
  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(&broad_addr, 0, sizeof(broad_addr));
  broad_addr.sin_family = AF_INET;
  broad_addr.sin_addr.s_addr = inet_addr(argv[1]);
  broad_addr.sin_port = htons(atoi(argv[2]));
  ret = setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt));
  if (ret == -1) {
    perror("setsockopt() failed");
    exit(EXIT_FAILURE);
  }
  fd = open("news_sender_brd.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';
    printf("buf: %s\n", buf);
    sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&broad_addr,
           sizeof(broad_addr));
    sleep(2);
  }
  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   $0x1,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1251 <main+0x51>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc2(%rip),%rsi
call   10c0 <fprintf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1291 <main+0x91>
lea    0xd99(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <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    131f <main+0x11f>
lea    0xd1b(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%esi
lea    0xd0c(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    135b <main+0x15b>
lea    0xd05(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    1360 <main+0x160>
mov    -0x28(%rbp),%edi
lea    -0x3a(%rbp),%rsi
mov    $0x9,%edx
call   10a0 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    13d6 <main+0x1d6>
movslq -0x30(%rbp),%rax
movb   $0x0,-0x3a(%rbp,%rax,1)
lea    -0x3a(%rbp),%rsi
lea    0xcca(%rip),%rdi
call   1060 <printf@plt>
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   1080 <sendto@plt>
mov    $0x2,%edi
call   1110 <sleep@plt>
jmp    1360 <main+0x160>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
movl   $0x1,0x4(%rsp)
cmp    $0x3,%edi
jne    136d <main+0x16d>
mov    0x2db9(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1387 <main+0x187>
mov    %eax,%r15d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x8(%rbx),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2d62(%rip),%rax
mov    (%rax),%esi
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1390 <main+0x190>
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
lea    0xd7e(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1399 <main+0x199>
mov    %eax,%ebp
lea    0x16(%rsp),%rsi
mov    %eax,%edi
mov    $0x9,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    134f <main+0x14f>
lea    0xd72(%rip),%r14
lea    0x16(%rsp),%rbx
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%eax
movb   $0x0,0x16(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    $0x2,%edi
call   1110 <sleep@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x9,%edx
call   10a0 <read@plt>
test   %eax,%eax
jg     1300 <main+0x100>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r15d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc80(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    13a5 <main+0x1a5>
lea    0xc89(%rip),%rdi
jmp    13a0 <main+0x1a0>
lea    0xc90(%rip),%rdi
jmp    13a0 <main+0x1a0>
lea    0xcad(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
call   1100 <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"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [20 x i8] c"setsockopt() failed\00"
@.str.3 = [18 x i8] c"news_sender_brd.c\00"
@O_RDONLY = global i32 0
@.str.4 = [14 x i8] c"open() failed\00"
@.str.5 = [9 x i8] c"buf: %s\0A\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 1, 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* @SOL_SOCKET
%51 = load i32, i32* @SO_BROADCAST
%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 ([18 x i8], [18 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 %87
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 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%79 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %78)
%80 = load i32, i32* %6
%81 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%82 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%83 = call i32 @strlen(i8* %82)
%84 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%85 = call i32 @sendto(i32 %80, i8* %81, i32 %83, i32 0, %struct.sockaddr* %84, i32 12)
%86 = call i32 @sleep(i32 2)
br label %69
87: ; preds = %69
%88 = load i32, i32* %9
%89 = call i32 @close(i32 %88)
%90 = load i32, i32* %6
%91 = call i32 @close(i32 %90)
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"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [20 x i8] c"setsockopt() failed\00"
@.str.3 = [18 x i8] c"news_sender_brd.c\00"
@O_RDONLY = global i32 0
@.str.4 = [14 x i8] c"open() failed\00"
@.str.5 = [9 x i8] c"buf: %s\0A\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 1, 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* @SOL_SOCKET
%39 = load i32, i32* @SO_BROADCAST
%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 ([18 x i8], [18 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 %69
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 ], [ %67, %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 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%64 = call i32 @strlen(i8* %8)
%65 = call i32 @sendto(i32 %19, i8* %8, i32 %64, i32 0, %struct.sockaddr* %54, i32 12)
%66 = call i32 @sleep(i32 2)
%67 = call i32 @read(i32 %48, i8* %8, i32 9)
%68 = icmp sgt i32 %67, 0
br i1 %68, label %59, label %69
69: ; preds = %59, %50
%70 = call i32 @close(i32 %48)
%71 = call i32 @close(i32 %19)
ret i32 0
}