#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 /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ op;
typedef int /*<<< orphan*/ caddr;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int fd;
  char buf[1024] = {};
  struct sockaddr_in addr = {};
  struct sockaddr_in caddr = {};
  if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
    do {
      fprintf(stderr, "[%s][%d] %s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day13/bcastr.c",
              26, "socket", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  int op = 1;
  setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &op, sizeof(op));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(9898);
  inet_pton(AF_INET, "192.168.0.255", &addr.sin_addr);
  if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
    do {
      fprintf(stderr, "[%s][%d] %s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day13/bcastr.c",
              34, "bind", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  socklen_t len = sizeof(caddr);
  recvfrom(fd, buf, 1024, 0, (struct sockaddr *)&caddr, &len);
  printf("%s:buf=%s\n", inet_ntoa(caddr.sin_addr), buf);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1298 <main+0xc8>
jmp    1245 <main+0x75>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x43c(%rbp),%edi
mov    %rax,%r9
lea    0xd8e(%rip),%rsi
lea    0xd97(%rip),%rdx
mov    $0x1a,%ecx
lea    0xe20(%rip),%r8
call   1090 <fprintf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x1,-0x434(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d3c(%rip),%rax
mov    (%rax),%esi
mov    0x2cf3(%rip),%rax
mov    (%rax),%edx
lea    -0x434(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    $0x26aa,%edi
call   1050 <htons@plt>
mov    %eax,-0x41c(%rbp)
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rdx
lea    0xdad(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1379 <main+0x1a9>
jmp    1326 <main+0x156>
mov    0x2c9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x440(%rbp)
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x440(%rbp),%edi
mov    %rax,%r9
lea    0xcad(%rip),%rsi
lea    0xcb6(%rip),%rdx
mov    $0x22,%ecx
lea    0xd54(%rip),%r8
call   1090 <fprintf@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0xc,-0x438(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x430(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x438(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    -0x430(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    -0x410(%rbp),%rdx
lea    0xcfc(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x438,%rsp
lea    0x30(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1070 <memset@plt>
movl   $0x0,0x20(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12f6 <main+0x126>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2d85(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x28(%rsp)
mov    $0x26aa,%edi
call   1050 <htons@plt>
mov    %eax,0x24(%rsp)
mov    (%r14),%edi
lea    0xe32(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdx
call   10a0 <inet_pton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
je     132b <main+0x15b>
movl   $0xc,0x8(%rsp)
lea    0x30(%rsp),%r14
lea    0x10(%rsp),%r8
lea    0x8(%rsp),%r9
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
mov    0x10(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xde8(%rip),%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1060 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2ccb(%rip),%rax
mov    (%rax),%ebx
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xcec(%rip),%rsi
lea    0xcf5(%rip),%rdx
lea    0xd83(%rip),%r8
mov    %ebx,%edi
mov    $0x1a,%ecx
jmp    135e <main+0x18e>
mov    0x2c96(%rip),%rax
mov    (%rax),%ebx
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xcb7(%rip),%rsi
lea    0xcc0(%rip),%rdx
lea    0xd63(%rip),%r8
mov    %ebx,%edi
mov    $0x22,%ecx
mov    %rax,%r9
call   1090 <fprintf@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d] %s %s\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day13/bcastr.c\00"
@.str.2 = [7 x i8] c"socket\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@.str.3 = [14 x i8] c"192.168.0.255\00"
@.str.4 = [5 x i8] c"bind\00"
@.str.5 = [11 x i8] c"%s:buf=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [1024 x i8]* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %24
15: ; preds = %0
br label %16
16: ; preds = %15
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %0
store i32 1, i32* %6
%25 = load i32, i32* %2
%26 = load i32, i32* @SOL_SOCKET
%27 = load i32, i32* @SO_REUSEADDR
%28 = call i32 @setsockopt(i32 %25, i32 %26, i32 %27, i32* %6, i32 4)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %29, i32* %30
%31 = call i32 @htons(i32 9898)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %31, i32* %32
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%35 = call i32 @inet_pton(i32 %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* %34)
%36 = load i32, i32* %2
%37 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%38 = call i32 @bind(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %49
40: ; preds = %24
br label %41
41: ; preds = %40
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; No predecessors!
br label %49
49: ; preds = %48, %24
store i32 12, i32* %7
%50 = load i32, i32* %2
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%52 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%53 = call i32 @recvfrom(i32 %50, i8* %51, i32 1024, i32 0, %struct.sockaddr* %52, i32* %7)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i8* @inet_ntoa(i32 %55)
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%58 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %57)
%59 = load i32, i32* %2
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d] %s %s\0A\00"
@.str.1 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day13/bcastr.c\00"
@.str.2 = [7 x i8] c"socket\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@.str.3 = [14 x i8] c"192.168.0.255\00"
@.str.4 = [5 x i8] c"bind\00"
@.str.5 = [11 x i8] c"%s:buf=%s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 0, i32* %8
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %0
%22 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_REUSEADDR
%25 = call i32 @setsockopt(i32 %12, i32 %23, i32 %24, i32* %4, i32 4)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @htons(i32 9898)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%32 = call i32 @inet_pton(i32 %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* %31)
%33 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%34 = call i32 @bind(i32 %12, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %43
36: ; preds = %21
%37 = load i32, i32* @stderr
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.1, i64 0, i64 0), i32 34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %21
%44 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%45 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%46 = call i32 @recvfrom(i32 %12, i8* %6, i32 1024, i32 0, %struct.sockaddr* %45, i32* %5)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%48 = load i32, i32* %47
%49 = call i8* @inet_ntoa(i32 %48)
%50 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %49, i8* %6)
%51 = call i32 @close(i32 %12)
ret i32 0
}