#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ cli_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_in serv_addr, cli_addr;
  fd_set readfds;
  int sockfd;
  int i;
  socklen_t slen = sizeof(cli_addr);
  char buf[64];
  int running;
  int cmpval;
  int nvals;
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
    err("could not open socket");
  bzero(&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(10001);
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
    err("could not bind");
  FD_ZERO(&readfds);
  FD_SET(sockfd, &readfds);
  while (select(sockfd + 1, &readfds, NULL, NULL, NULL)) {
    recvfrom(sockfd, buf, 64, 0, (struct sockaddr *)&cli_addr, &slen);
    cmpval = strncmp(buf, "run", 3);
    if (cmpval == 0) {
      nvals = atoi(buf + 3);
      printf("nvals %d\n", nvals);
    }
    printf("recieved packet from %s:%d\nData: %s\n\n",
           inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port), buf);
    memset(&buf[0], 0, sizeof(buf));
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x40(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    1268 <main+0x58>
lea    0xd9d(%rip),%rdi
call   10c0 <err@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2711,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12c6 <main+0xb6>
lea    0xd55(%rip),%rdi
call   10c0 <err@plt>
lea    -0x34(%rbp),%rdi
call   10a0 <FD_ZERO@plt>
mov    -0x38(%rbp),%edi
lea    -0x34(%rbp),%rsi
call   1120 <FD_SET@plt>
mov    -0x38(%rbp),%edi
add    $0x1,%edi
lea    -0x34(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10b0 <select@plt>
cmp    $0x0,%rax
je     13b0 <main+0x1a0>
mov    -0x38(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0x40,%edx
xor    %ecx,%ecx
lea    -0x40(%rbp),%r9
call   10d0 <recvfrom@plt>
lea    -0x80(%rbp),%rdi
lea    0xd00(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0x0,-0x88(%rbp)
jne    1369 <main+0x159>
lea    -0x80(%rbp),%rdi
add    $0x3,%rdi
call   1110 <atoi@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x98(%rbp)
mov    -0x30(%rbp),%edi
call   10e0 <ntohs@plt>
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
lea    -0x80(%rbp),%rcx
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1080 <memset@plt>
jmp    12db <main+0xcb>
mov    -0x38(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
movl   $0xc,0x8(%rsp)
mov    0x2dbb(%rip),%r14
mov    (%r14),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
mov    0x2d80(%rip),%rax
mov    (%rax),%edx
call   1130 <socket@plt>
mov    %eax,%ebp
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    125d <main+0x4d>
lea    0xda8(%rip),%rdi
call   10c0 <err@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x2711,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12b7 <main+0xa7>
lea    0xd64(%rip),%rdi
call   10c0 <err@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <FD_ZERO@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1120 <FD_SET@plt>
add    $0x1,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
test   %rax,%rax
je     139f <main+0x18f>
lea    0x30(%rsp),%rbx
lea    0xd3b(%rip),%r12
lea    0xc(%rsp),%r13
jmp    134c <main+0x13c>
nop
mov    0x24(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r14
mov    0x20(%rsp),%edi
call   10e0 <ntohs@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1080 <memset@plt>
mov    %ebp,%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <select@plt>
test   %rax,%rax
je     139f <main+0x18f>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
lea    0x8(%rsp),%r9
call   10d0 <recvfrom@plt>
mov    %rbx,%rdi
lea    0xcb3(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1300 <main+0xf0>
lea    0x33(%rsp),%rdi
call   1110 <atoi@plt>
lea    0xc98(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1300 <main+0xf0>
mov    %r15d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [22 x i8] c"could not open socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [15 x i8] c"could not bind\00"
@.str.2 = [4 x i8] c"run\00"
@.str.3 = [10 x i8] c"nvals %d\0A\00"
@.str.4 = [38 x i8] c"recieved packet from %s:%d\0AData: %s\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [64 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %11
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = load i32, i32* @IPPROTO_UDP
%19 = call i32 @socket(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %9
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @err(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i32 10001)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = load i32, i32* %9
%34 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%35 = call i32 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %23
%40 = call i32 @FD_ZERO(i32* %8)
%41 = load i32, i32* %9
%42 = call i32 @FD_SET(i32 %41, i32* %8)
br label %43
43: ; preds = %63, %39
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
%46 = call i64 @select(i32 %45, i32* %8, i32* null, i32* null, i32* null)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %75
48: ; preds = %43
%49 = load i32, i32* %9
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%51 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%52 = call i32 @recvfrom(i32 %49, i8* %50, i32 64, i32 0, %struct.sockaddr* %51, i32* %11)
%53 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%54 = call i32 @strncmp(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
store i32 %54, i32* %14
%55 = load i32, i32* %14
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %48
%58 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%59 = getelementptr inbounds i8, i8* %58, i64 3
%60 = call i32 @atoi(i8* %59)
store i32 %60, i32* %15
%61 = load i32, i32* %15
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %57, %48
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%65 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i8* @inet_ntoa(i32 %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @ntohs(i32 %69)
%71 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %67, i32 %70, i8* %71)
%73 = getelementptr inbounds [64 x i8], [64 x i8]* %12, i64 0, i64 0
%74 = call i32 @memset(i8* %73, i32 0, i32 64)
br label %43
75: ; preds = %43
%76 = load i32, i32* %9
%77 = call i32 @close(i32 %76)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [22 x i8] c"could not open socket\00"
@INADDR_ANY = global i32 0
@.str.1 = [15 x i8] c"could not bind\00"
@.str.2 = [4 x i8] c"run\00"
@.str.3 = [10 x i8] c"nvals %d\0A\00"
@.str.4 = [38 x i8] c"recieved packet from %s:%d\0AData: %s\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = load i32, i32* @IPPROTO_UDP
%16 = tail call i32 @socket(i32 %13, i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = tail call i32 @err(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %2
%21 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 10001)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = tail call i32 @htonl(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i32 @bind(i32 %16, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 @err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %20
%35 = call i32 @FD_ZERO(i32* %5)
%36 = call i32 @FD_SET(i32 %16, i32* %5)
%37 = add nsw i32 %16, 1
%38 = call i64 @select(i32 %37, i32* %5, i32* null, i32* null, i32* null)
%39 = icmp eq i64 %38, 0
br i1 %39, label %61, label %40
40: ; preds = %34
%41 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 3
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
br label %45
45: ; preds = %40, %52
%46 = call i32 @recvfrom(i32 %16, i8* %12, i32 64, i32 0, %struct.sockaddr* %41, i32* %6)
%47 = call i32 @strncmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = call i32 @atoi(i8* %42)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %45
%53 = load i32, i32* %43
%54 = call i8* @inet_ntoa(i32 %53)
%55 = load i32, i32* %44
%56 = call i32 @ntohs(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %54, i32 %56, i8* %12)
%58 = call i32 @memset(i8* %12, i32 0, i32 64)
%59 = call i64 @select(i32 %37, i32* %5, i32* null, i32* null, i32* null)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %45
61: ; preds = %52, %34
%62 = call i32 @close(i32 %16)
ret i32 0
}