#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_port;
};
typedef int /*<<< orphan*/ so_broadcast;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int SetBroadcast(int sock, struct sockaddr_in *broadcast_addr) {
  int ret = -1;
  int so_broadcast = 1;
  broadcast_addr->sin_port = htons(8888);
  ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &so_broadcast,
                   sizeof(so_broadcast));
  if (0 > ret) {
    perror("client set broadcast err");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<SetBroadcast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jle    11a9 <SetBroadcast+0x79>
lea    0xe68(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <SetBroadcast+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetBroadcast>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x1,0x4(%rsp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,(%rbx)
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     117f <SetBroadcast+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    1178 <SetBroadcast+0x48>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str = [25 x i8] c"client set broadcast err\00"
define i32 @SetBroadcast(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
store i32 -1, i32* %6
store i32 1, i32* %7
%8 = call i32 @htons(i32 8888)
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = load i32, i32* %4
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_BROADCAST
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %7, i32 4)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sgt i32 0, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %20
19: ; preds = %2
store i32 0, i32* %3
br label %20
20: ; preds = %19, %17
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str = [25 x i8] c"client set broadcast err\00"
define i32 @SetBroadcast(i32 %0, %struct.sockaddr_in* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%5 = tail call i32 @htons(i32 8888)
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %5, i32* %6
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_BROADCAST
%9 = call i32 @setsockopt(i32 %0, i32 %7, i32 %8, i32* %3, i32 4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %2, %11
%14 = phi i32 [ -1, %11 ], [ 0, %2 ]
ret i32 %14
}