#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 /*<<< 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_BINDTODEVICE;
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);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(void) {
  int fd;
  struct sockaddr_in addr = {};
  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/mult/bcsts.c",
              24, "socket", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  int op = 1;
  setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, "eth0", 5);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(9898);
  inet_pton(AF_INET, "224.2.2.2", &addr.sin_addr);
  sendto(fd, "multi cast", strlen("multi cast"), 0, (struct sockaddr *)&addr,
         sizeof(addr));
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1246 <main+0x96>
jmp    11f9 <main+0x49>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%r9
lea    0xde0(%rip),%rsi
lea    0xde9(%rip),%rdx
mov    $0x18,%ecx
lea    0xe76(%rip),%r8
call   1090 <fprintf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
lea    0xe47(%rip),%rcx
mov    $0x5,%r8d
call   1030 <setsockopt@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x26aa,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xe0c(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    -0x18(%rbp),%r8
lea    0xdf7(%rip),%rsi
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,(%rsp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     1264 <main+0xc4>
mov    %eax,%ebx
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    0x2dc4(%rip),%rax
mov    (%rax),%edx
lea    0xec3(%rip),%rcx
mov    %ebx,%edi
mov    $0x5,%r8d
call   1030 <setsockopt@plt>
mov    0x2ddf(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x26aa,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%r14),%edi
lea    0xe95(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
call   1090 <inet_pton@plt>
lea    0xe8d(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d5d(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd7e(%rip),%rsi
lea    0xd87(%rip),%rdx
lea    0xe19(%rip),%r8
mov    %ebx,%edi
mov    $0x18,%ecx
mov    %rax,%r9
call   1080 <fprintf@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10a0 <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 = [153 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/mult/bcsts.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_BINDTODEVICE = global i32 0
@.str.3 = [5 x i8] c"eth0\00"
@AF_INET = global i32 0
@.str.4 = [10 x i8] c"224.2.2.2\00"
@.str.5 = [11 x i8] c"multi cast\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %0
br label %11
11: ; preds = %10
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %0
store i32 1, i32* %4
%20 = load i32, i32* %2
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_BINDTODEVICE
%23 = call i32 @setsockopt(i32 %20, i32 %21, i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 5)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 9898)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%30 = call i32 @inet_pton(i32 %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* %29)
%31 = load i32, i32* %2
%32 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i32 @sendto(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %32, i32 0, %struct.sockaddr* %33, i32 12)
%35 = load i32, i32* %2
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* %1
ret i32 %37
}

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 = [153 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/mult/bcsts.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_BINDTODEVICE = global i32 0
@.str.3 = [5 x i8] c"eth0\00"
@AF_INET = global i32 0
@.str.4 = [10 x i8] c"224.2.2.2\00"
@.str.5 = [11 x i8] c"multi cast\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 0, i32* %3
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([153 x i8], [153 x i8]* @.str.1, i64 0, i64 0), i32 24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_BINDTODEVICE
%18 = tail call i32 @setsockopt(i32 %6, i32 %16, i32 %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 5)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 9898)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%25 = call i32 @inet_pton(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* %24)
%26 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%27 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%28 = call i32 @sendto(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %26, i32 0, %struct.sockaddr* %27, i32 12)
%29 = call i32 @close(i32 %6)
ret i32 0
}