#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*/ servAddr;
typedef int /*<<< orphan*/ cliAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(char *, int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, 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 main(int argc, char *argv[]) {
  int sd, rc, n, cliLen;
  struct sockaddr_in cliAddr, servAddr;
  char msg[100];
  int broadcast = 1;
  sd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sd < 0) {
    printf("%s: cannot open socket \n", argv[0]);
    exit(1);
  }
  if (setsockopt(sd, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof broadcast) ==
      -1) {
    perror("setsockopt (SO_BROADCAST)");
    exit(1);
  }
  servAddr.sin_family = AF_INET;
  servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servAddr.sin_port = htons(1500);
  rc = bind(sd, (struct sockaddr *)&servAddr, sizeof(servAddr));
  if (rc < 0) {
    printf("%s: cannot bind port number %d \n", argv[0], 1500);
    exit(1);
  }
  printf("%s: waiting for data on port UDP %u\n", argv[0], 1500);
  cliLen = sizeof(cliAddr);
  while (1) {
    memset(msg, 0x0, 100);
    n = recvfrom(sd, msg, 100, 0, (struct sockaddr *)&cliAddr, &cliLen);
    if (n < 0) {
      printf("%s: cannot receive data \n", argv[0]);
      continue;
    }
    printf("%s: from %s:UDP%u : %s \n", argv[0], inet_ntoa(cliAddr.sin_addr),
           ntohs(cliAddr.sin_port), msg);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0xb4(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1228 <main+0x68>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
lea    -0xb4(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    126e <main+0xae>
lea    0xdba(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x5dc,%edi
call   1050 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12da <main+0x11a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd6f(%rip),%rdi
mov    $0x5dc,%edx
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd6c(%rip),%rdi
mov    $0x5dc,%edx
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xc,-0x20(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1080 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x20(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1353 <main+0x193>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12fb <main+0x13b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0xc0(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <ntohs@plt>
mov    -0xc8(%rbp),%rsi
mov    -0xc0(%rbp),%rdx
mov    %eax,%ecx
lea    -0xb0(%rbp),%r8
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12fb <main+0x13b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rsi,(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2dfc(%rip),%rbx
mov    (%rbx),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     1312 <main+0x152>
mov    %eax,%ebp
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1331 <main+0x171>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x5dc,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    (%rsp),%rcx
mov    (%rcx),%rsi
test   %eax,%eax
js     1347 <main+0x187>
lea    0xdda(%rip),%rdi
mov    $0x5dc,%edx
xor    %eax,%eax
call   1060 <printf@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%r12
jmp    12ce <main+0x10e>
nop
mov    0x24(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r14
mov    0x20(%rsp),%edi
call   10a0 <ntohs@plt>
lea    0xdd7(%rip),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1080 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1090 <recvfrom@plt>
mov    (%rsp),%rcx
mov    (%rcx),%r13
test   %eax,%eax
jns    12a0 <main+0xe0>
lea    0xd73(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ce <main+0x10e>
mov    (%rsp),%rax
mov    (%rax),%rsi
lea    0xce0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xce1(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xce5(%rip),%rdi
mov    $0x5dc,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <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 = [25 x i8] c"%s: cannot open socket \0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [26 x i8] c"setsockopt (SO_BROADCAST)\00"
@INADDR_ANY = global i32 0
@.str.2 = [33 x i8] c"%s: cannot bind port number %d \0A\00"
@.str.3 = [37 x i8] c"%s: waiting for data on port UDP %u\0A\00"
@.str.4 = [26 x i8] c"%s: cannot receive data \0A\00"
@.str.5 = [25 x i8] c"%s: from %s:UDP%u : %s \0A\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 i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca [100 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %13
%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 %25
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i32, i32* %6
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_BROADCAST
%29 = call i32 @setsockopt(i32 %26, i32 %27, i32 %28, i32* %13, i32 4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %25
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* @INADDR_ANY
%38 = call i32 @htonl(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = call i32 @htons(i32 1500)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %41, i32* %42
%43 = load i32, i32* %6
%44 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 12)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %34
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %51, i32 1500)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %34
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 0
%57 = load i8*, i8** %56
%58 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %57, i32 1500)
store i32 12, i32* %9
br label %59
59: ; preds = %54, %68, %73
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%61 = call i32 @memset(i8* %60, i32 0, i32 100)
%62 = load i32, i32* %6
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%64 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%65 = call i32 @recvfrom(i32 %62, i8* %63, i32 100, i32 0, %struct.sockaddr* %64, i32* %9)
store i32 %65, i32* %8
%66 = load i32, i32* %8
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %59
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %71)
br label %59
73: ; preds = %59
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 0
%76 = load i8*, i8** %75
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%78 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i8* @inet_ntoa(i32 %79)
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 @ntohs(i32 %82)
%84 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%85 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %76, i8* %80, i32 %83, i8* %84)
br label %59
}

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 = [25 x i8] c"%s: cannot open socket \0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.1 = [26 x i8] c"setsockopt (SO_BROADCAST)\00"
@INADDR_ANY = global i32 0
@.str.2 = [33 x i8] c"%s: cannot bind port number %d \0A\00"
@.str.3 = [37 x i8] c"%s: waiting for data on port UDP %u\0A\00"
@.str.4 = [26 x i8] c"%s: cannot receive data \0A\00"
@.str.5 = [25 x i8] c"%s: from %s:UDP%u : %s \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i8*, i8** %1
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_BROADCAST
%24 = call i32 @setsockopt(i32 %15, i32 %22, i32 %23, i32* %7, i32 4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = call i32 @htonl(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %33, i32* %34
%35 = call i32 @htons(i32 1500)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %35, i32* %36
%37 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%38 = call i32 @bind(i32 %15, %struct.sockaddr* %37, i32 12)
%39 = icmp slt i32 %38, 0
%40 = load i8*, i8** %1
br i1 %39, label %41, label %44
41: ; preds = %29
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %40, i32 1500)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %29
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %40, i32 1500)
store i32 12, i32* %3
%46 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
br label %49
49: ; preds = %56, %44
%50 = call i32 @memset(i8* %11, i32 0, i32 100)
%51 = call i32 @recvfrom(i32 %15, i8* %11, i32 100, i32 0, %struct.sockaddr* %46, i32* %3)
%52 = icmp slt i32 %51, 0
%53 = load i8*, i8** %1
br i1 %52, label %54, label %57
54: ; preds = %49
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %56
56: ; preds = %54, %57
br label %49
57: ; preds = %49
%58 = load i32, i32* %47
%59 = call i8* @inet_ntoa(i32 %58)
%60 = load i32, i32* %48
%61 = call i32 @ntohs(i32 %60)
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %53, i8* %59, i32 %61, i8* %11)
br label %56
}