#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 */

/* Type definitions */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ displayError(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int mkaddr(struct sockaddr_in *, int *, char *, char *);
int /*<<< orphan*/ putchar(char);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int x;
  struct sockaddr_in adr;
  char dgram[512];
  char *bc_addr = "127.255.255.255:9097";
  if (argc > 1)
    bc_addr = argv[1];
  int s = socket(AF_INET, SOCK_DGRAM, 0);
  if (s == -1)
    displayError("socket()");
  int len_inet = sizeof adr;
  int z = mkaddr(&adr, &len_inet, bc_addr, "udp");
  if (z == -1)
    displayError("Bad broadcast address");
  static int so_reuseaddr = 1;
  z = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &so_reuseaddr,
                 sizeof so_reuseaddr);
  if (z == -1)
    displayError("setsockopt(SO_REUSEADDR)");
  z = bind(s, (struct sockaddr *)&adr, len_inet);
  if (z == -1)
    displayError("bind(2)");
  for (;;) {
    z = recvfrom(s, dgram, sizeof dgram, 0, (struct sockaddr *)&adr, &x);
    if (z < 0)
      displayError("recvfrom(2)");
    fwrite(dgram, z, 1, stdout);
    putchar('\n');
    fflush(stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x228(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11d0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x228(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x22c(%rbp)
cmpl   $0xffffffff,-0x22c(%rbp)
jne    1208 <main+0x78>
lea    0xe12(%rip),%rdi
call   1060 <displayError@plt>
movl   $0x4,-0x230(%rbp)
mov    -0x228(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x230(%rbp),%rsi
lea    0xdf3(%rip),%rcx
call   1050 <mkaddr@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0xffffffff,-0x234(%rbp)
jne    124f <main+0xbf>
lea    0xdd8(%rip),%rdi
call   1060 <displayError@plt>
mov    -0x22c(%rbp),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
lea    0x2dfa(%rip),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0xffffffff,-0x234(%rbp)
jne    1298 <main+0x108>
lea    0xda5(%rip),%rdi
call   1060 <displayError@plt>
mov    -0x22c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x230(%rbp),%edx
call   1090 <bind@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0xffffffff,-0x234(%rbp)
jne    12cc <main+0x13c>
lea    0xd8a(%rip),%rdi
call   1060 <displayError@plt>
jmp    12d1 <main+0x141>
mov    -0x22c(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x18(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x14(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x234(%rbp)
cmpl   $0x0,-0x234(%rbp)
jge    1311 <main+0x181>
lea    0xd4d(%rip),%rdi
call   1060 <displayError@plt>
lea    -0x220(%rbp),%rdi
mov    -0x234(%rbp),%esi
mov    0x2ca3(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    12d1 <main+0x141>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
cmp    $0x2,%edi
jl     11ac <main+0x1c>
mov    0x8(%rsi),%rbx
jmp    11b3 <main+0x23>
lea    0xe4d(%rip),%rbx
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
jne    11e0 <main+0x50>
lea    0xe3a(%rip),%rdi
call   1060 <displayError@plt>
movl   $0x4,0x8(%rsp)
lea    0xe2f(%rip),%rcx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <mkaddr@plt>
cmp    $0xffffffff,%eax
jne    1210 <main+0x80>
lea    0xe17(%rip),%rdi
call   1060 <displayError@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    0x2e3f(%rip),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1248 <main+0xb8>
lea    0xdf5(%rip),%rdi
call   1060 <displayError@plt>
mov    0x8(%rsp),%edx
mov    %rsp,%rsi
mov    %r14d,%edi
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    1268 <main+0xd8>
lea    0xdee(%rip),%rdi
call   1060 <displayError@plt>
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
lea    0xc(%rsp),%r13
mov    0x2d4c(%rip),%r12
jmp    12a6 <main+0x116>
xchg   %ax,%ax
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r12),%edi
call   1070 <fflush@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r13,%r9
call   1080 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1280 <main+0xf0>
lea    0xd8e(%rip),%rdi
call   1060 <displayError@plt>
jmp    1280 <main+0xf0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"127.255.255.255:9097\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.2 = [4 x i8] c"udp\00"
@.str.3 = [22 x i8] c"Bad broadcast address\00"
@main.so_reuseaddr = internal global i32 1
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [25 x i8] c"setsockopt(SO_REUSEADDR)\00"
@.str.5 = [8 x i8] c"bind(2)\00"
@.str.6 = [12 x i8] c"recvfrom(2)\00"
@stdout = global i32 0
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 [512 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %9
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %9
br label %19
19: ; preds = %15, %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @displayError(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
store i32 4, i32* %11
%28 = load i8*, i8** %9
%29 = call i32 @mkaddr(%struct.sockaddr_in* %7, i32* %11, i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @displayError(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %10
%36 = load i32, i32* @SOL_SOCKET
%37 = load i32, i32* @SO_REUSEADDR
%38 = call i32 @setsockopt(i32 %35, i32 %36, i32 %37, i32* @main.so_reuseaddr, i32 4)
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @displayError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %34
%44 = load i32, i32* %10
%45 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%46 = load i32, i32* %11
%47 = call i32 @bind(i32 %44, %struct.sockaddr* %45, i32 %46)
store i32 %47, i32* %12
%48 = load i32, i32* %12
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 @displayError(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %43
br label %53
53: ; preds = %62, %52
%54 = load i32, i32* %10
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%56 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%57 = call i32 @recvfrom(i32 %54, i8* %55, i32 512, i32 0, %struct.sockaddr* %56, i32* %6)
store i32 %57, i32* %12
%58 = load i32, i32* %12
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %53
%61 = call i32 @displayError(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %62
62: ; preds = %60, %53
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%64 = load i32, i32* %12
%65 = load i32, i32* @stdout
%66 = call i32 @fwrite(i8* %63, i32 %64, i32 1, i32 %65)
%67 = call i32 @putchar(i8 signext 10)
%68 = load i32, i32* @stdout
%69 = call i32 @fflush(i32 %68)
br label %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"127.255.255.255:9097\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [9 x i8] c"socket()\00"
@.str.2 = [4 x i8] c"udp\00"
@.str.3 = [22 x i8] c"Bad broadcast address\00"
@main.so_reuseaddr = internal global i32 1
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [25 x i8] c"setsockopt(SO_REUSEADDR)\00"
@.str.5 = [8 x i8] c"bind(2)\00"
@.str.6 = [12 x i8] c"recvfrom(2)\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [512 x i8]
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
br label %14
14: ; preds = %11, %2
%15 = phi i8* [ %13, %11 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %2 ]
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = tail call i32 @displayError(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
%23 = bitcast i32* %6 to i8*
store i32 4, i32* %6
%24 = call i32 @mkaddr(%struct.sockaddr_in* %4, i32* %6, i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @displayError(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_REUSEADDR
%31 = call i32 @setsockopt(i32 %18, i32 %29, i32 %30, i32* @main.so_reuseaddr, i32 4)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @displayError(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = load i32, i32* %6
%38 = call i32 @bind(i32 %18, %struct.sockaddr* %36, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @displayError(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
br label %43
43: ; preds = %42, %48
%44 = call i32 @recvfrom(i32 %18, i8* %9, i32 512, i32 0, %struct.sockaddr* %36, i32* %3)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @displayError(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = load i32, i32* @stdout
%50 = call i32 @fwrite(i8* %9, i32 %44, i32 1, i32 %49)
%51 = call i32 @putchar(i8 signext 10)
%52 = load i32, i32* @stdout
%53 = call i32 @fflush(i32 %52)
br label %43
}