#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 socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int 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;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int s, len, o, port = 6666;
  char buf[512];
  struct sockaddr_in addr;
  socklen_t addr_len = sizeof addr;
  if (argc > 1)
    port = atoi(argv[1]);
  s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  o = 1;
  len = 4;
  setsockopt(3, SOL_SOCKET, SO_REUSEADDR, &o, len);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr.s_addr = INADDR_ANY;
  bind(s, (struct sockaddr *)&addr, sizeof addr);
  for (;;) {
    len = recvfrom(s, buf, sizeof buf, 0, (struct sockaddr *)&addr, &addr_len);
    if (len < 0)
      break;
    if (write(1, buf, len) != len)
      fprintf(stderr, "WARNING: serial characters dropped\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1a0a,-0x20(%rbp)
movl   $0xc,-0x234(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x4,-0x18(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%r8d
mov    $0x3,%edi
lea    -0x1c(%rbp),%rcx
call   1030 <setsockopt@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x228(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x22c(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x230(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
lea    -0x230(%rbp),%r8
mov    $0x200,%edx
xor    %ecx,%ecx
lea    -0x234(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    128f <main+0x10f>
jmp    12c6 <main+0x146>
lea    -0x220(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
cmp    -0x18(%rbp),%eax
je     12c1 <main+0x141>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd44(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1259 <main+0xd9>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
movl   $0xc,0x8(%rsp)
mov    $0x1a0a,%ebx
cmp    $0x2,%edi
jl     11ae <main+0x2e>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,%r13d
movl   $0x1,0xc(%rsp)
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    $0x3,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%r9
mov    %r13d,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1070 <recvfrom@plt>
test   %eax,%eax
js     12c4 <main+0x144>
mov    %eax,%ebp
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0xd8e(%rip),%r12
jmp    129e <main+0x11e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1070 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
js     12c4 <main+0x144>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     1280 <main+0x100>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1060 <fprintf@plt>
jmp    1280 <main+0x100>
xor    %eax,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
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
@IPPROTO_UDP = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"WARNING: serial characters dropped\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 i32
%9 = alloca i32
%10 = alloca [512 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 6666, i32* %9
store i32 12, i32* %12
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %9
br label %20
20: ; preds = %15, %2
%21 = load i32, i32* @PF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = load i32, i32* @IPPROTO_UDP
%24 = call i32 @socket(i32 %21, i32 %22, i32 %23)
store i32 %24, i32* %6
store i32 1, i32* %8
store i32 4, i32* %7
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = load i32, i32* %7
%28 = call i32 @setsockopt(i32 3, i32 %25, i32 %26, i32* %8, i32 %27)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* %9
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i32, i32* %6
%38 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%39 = call i32 @bind(i32 %37, %struct.sockaddr* %38, i32 12)
br label %40
40: ; preds = %57, %20
%41 = load i32, i32* %6
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%43 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%44 = call i32 @recvfrom(i32 %41, i8* %42, i32 512, i32 0, %struct.sockaddr* %43, i32* %12)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %40
br label %58
48: ; preds = %40
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%50 = load i32, i32* %7
%51 = call i32 @write(i32 1, i8* %49, i32 %50)
%52 = load i32, i32* %7
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %57
57: ; preds = %54, %48
br label %40
58: ; preds = %47
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
@IPPROTO_UDP = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"WARNING: serial characters dropped\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
br label %16
16: ; preds = %12, %2
%17 = phi i32 [ %15, %12 ], [ 6666, %2 ]
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = load i32, i32* @IPPROTO_UDP
%21 = tail call i32 @socket(i32 %18, i32 %19, i32 %20)
store i32 1, i32* %3
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i32 @setsockopt(i32 3, i32 %22, i32 %23, i32* %3, i32 4)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i32 %17)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %29, i32* %30
%31 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%32 = call i32 @bind(i32 %21, %struct.sockaddr* %31, i32 12)
%33 = call i32 @recvfrom(i32 %21, i8* %8, i32 512, i32 0, %struct.sockaddr* %31, i32* %6)
%34 = icmp slt i32 %33, 0
br i1 %34, label %45, label %35
35: ; preds = %16, %42
%36 = phi i32 [ %43, %42 ], [ %33, %16 ]
%37 = call i32 @write(i32 1, i8* %8, i32 %36)
%38 = icmp eq i32 %37, %36
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %39, %35
%43 = call i32 @recvfrom(i32 %21, i8* %8, i32 512, i32 0, %struct.sockaddr* %31, i32* %6)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %35
45: ; preds = %42, %16
ret i32 0
}