#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 ssize_t;
typedef int /*<<< orphan*/ from;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ assert(int);
int bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sock, status;
  char buf[2048];
  ssize_t s;
  struct sockaddr_in from;
  const struct sockaddr *__from = (const struct sockaddr *)&from;
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  assert(sock != -1);
  from.sin_family = AF_INET;
  from.sin_port = htons(0xbeef);
  from.sin_addr.s_addr = INADDR_ANY;
  status = bind(sock, __from, sizeof(from));
  assert(!status);
  do {
    s = recv(sock, buf, sizeof(buf), 0);
    if (s == -1) {
      perror("recv");
      continue;
    }
    printf("Received %zd byte(s). buf[0] is '%c'\n", s, buf[0]);
  } while (s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x828(%rbp)
mov    $0xbeef,%edi
call   1040 <htons@plt>
mov    %eax,-0x82c(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x830(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x838(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    1256 <main+0xe6>
lea    0xdb4(%rip),%rdi
call   1080 <perror@plt>
jmp    126f <main+0xff>
mov    -0x824(%rbp),%esi
lea    0xda2(%rip),%rdi
movsbl -0x820(%rbp),%edx
call   1050 <printf@plt>
cmpl   $0x0,-0x824(%rbp)
jne    121c <main+0xac>
xor    %eax,%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0xbeef,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
lea    0x10(%rsp),%r14
lea    0xe09(%rip),%r15
lea    0xe07(%rip),%r12
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     122d <main+0xbd>
movsbl 0x10(%rsp),%edx
mov    %r12,%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
test   %ebp,%ebp
jne    1200 <main+0x90>
jmp    1239 <main+0xc9>
mov    %r15,%rdi
call   1080 <perror@plt>
test   %ebp,%ebp
jne    1200 <main+0x90>
xor    %eax,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [5 x i8] c"recv\00"
@.str.1 = [38 x i8] c"Received %zd byte(s). buf[0] is '%c'\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 [2048 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
store %struct.sockaddr* %12, %struct.sockaddr** %11
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, -1
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 48879)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @INADDR_ANY
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %6
%28 = load %struct.sockaddr*, %struct.sockaddr** %11
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 12)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
br label %35
35: ; preds = %48, %2
%36 = load i32, i32* %6
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%38 = call i32 @recv(i32 %36, i8* %37, i32 2048, i32 0)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %48
43: ; preds = %35
%44 = load i32, i32* %9
%45 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%46 = load i8, i8* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %44, i8 signext %46)
br label %48
48: ; preds = %43, %41
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %35, label %51
51: ; preds = %48
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
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [5 x i8] c"recv\00"
@.str.1 = [38 x i8] c"Received %zd byte(s). buf[0] is '%c'\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2048 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp ne i32 %10, -1
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 48879)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = call i32 @bind(i32 %10, %struct.sockaddr* %7, i32 12)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
br label %24
24: ; preds = %32, %2
%25 = call i32 @recv(i32 %10, i8* %5, i32 2048, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %32
29: ; preds = %24
%30 = load i8, i8* %5
%31 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8 signext %30)
br label %32
32: ; preds = %29, %27
%33 = icmp eq i32 %25, 0
br i1 %33, label %34, label %24
34: ; preds = %32
ret i32 0
}