#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ opt;
typedef int /*<<< orphan*/ dr;

/* Variables and functions */
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*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int fd;
  int opt = 1;
  struct sockaddr_in dr;
  char buf[100];
  int r;
  fd = socket(PF_INET, SOCK_DGRAM, 0);
  if (fd == -1) {
    printf("create socket : %m\n");
    exit(-1);
  }
  r = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
  if (r == -1) {
    printf("socket option set : %m\n");
    exit(-1);
  }
  dr.sin_family = PF_INET;
  dr.sin_port = htons(8888);
  dr.sin_addr.s_addr = inet_addr("192.168.137.255");
  r = bind(fd, (struct sockaddr *)&dr, sizeof(dr));
  if (r == -1) {
    printf("bind socket : %m\n");
    exit(-1);
  }
  r = recv(fd, buf, 100, 0);
  if (r > 0) {
    buf[r] = 0;
    printf("cast data : %s\n", buf);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e7 <main+0x57>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    1236 <main+0xa6>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xdd6(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0xffffffff,-0x84(%rbp)
jne    129a <main+0x10a>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jle    12de <main+0x14e>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e27(%rip),%r14
mov    (%r14),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1274 <main+0xe4>
mov    %eax,%ebx
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     127d <main+0xed>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe1c(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     1286 <main+0xf6>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1260 <main+0xd0>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xdfa(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd85(%rip),%rdi
jmp    128d <main+0xfd>
lea    0xd90(%rip),%rdi
jmp    128d <main+0xfd>
lea    0xdaf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [20 x i8] c"create socket : %m\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [24 x i8] c"socket option set : %m\0A\00"
@.str.2 = [16 x i8] c"192.168.137.255\00"
@.str.3 = [18 x i8] c"bind socket : %m\0A\00"
@.str.4 = [16 x i8] c"cast data : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [100 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = load i32, i32* %2
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %3, i32 4)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %15
%26 = load i32, i32* @PF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @htons(i32 8888)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %28, i32* %29
%30 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = load i32, i32* %2
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i32 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %25
%42 = load i32, i32* %2
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%44 = call i32 @recv(i32 %42, i8* %43, i32 100, i32 0)
store i32 %44, i32* %6
%45 = load i32, i32* %6
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %49
store i8 0, i8* %50
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %47, %41
%54 = load i32, i32* %2
%55 = call i32 @close(i32 %54)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [20 x i8] c"create socket : %m\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [24 x i8] c"socket option set : %m\0A\00"
@.str.2 = [16 x i8] c"192.168.137.255\00"
@.str.3 = [18 x i8] c"bind socket : %m\0A\00"
@.str.4 = [16 x i8] c"cast data : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca [100 x i8]
%4 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_REUSEADDR
%17 = call i32 @setsockopt(i32 %9, i32 %15, i32 %16, i32* %1, i32 4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %14
%23 = load i32, i32* @PF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 8888)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %25, i32* %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i32 @bind(i32 %9, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %22
%36 = call i32 @recv(i32 %9, i8* %6, i32 100, i32 0)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = zext i32 %36 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %42
42: ; preds = %38, %35
%43 = call i32 @close(i32 %9)
ret i32 0
}