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

/* Variables and functions */
void *AF_INET;
int EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int const);
int /*<<< orphan*/ inet_addr(char const *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int peekSensor();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
void main() {
  int sock;
  struct sockaddr_in server, client;
  int recvd, snd;
  int structlength;
  const char *server_ip = "127.0.0.1";
  const int port = 8888;
  char recvBuf[2000], sendBuf[2000];
  char message[] = "I have received: \n";
  memset((char *)&server, 0, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr(server_ip);
  server.sin_port = htons(port);
  memset((char *)&client, 0, sizeof(client));
  client.sin_family = AF_INET;
  client.sin_addr.s_addr = htonl(INADDR_ANY);
  client.sin_port = htons(port);
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    printf("socket create error!\n");
    exit(1);
  }
  structlength = sizeof(server);
  if (bind(sock, (struct sockaddr *)&server, structlength) < 0) {
    printf("socket bind error!\n");
    perror("bind");
    exit(1);
  }
  int phpCmd = 0;
  while (1) {
    structlength = sizeof(client);
    printf("waiting.......\n");
    recvd = recvfrom(sock, recvBuf, sizeof(recvBuf), 0,
                     (struct sockaddr *)&client, &structlength);
    if (recvd < 0) {
      perror("recvfrom");
      exit(EXIT_FAILURE);
    } else {
      printf("1. received: %s\n", recvBuf);
      memset(message, 0, strlen(message));
      memcpy(message, recvBuf, strlen(recvBuf));
      phpCmd = 1;
    }
    if (1 == phpCmd) {
      printf("2. do command\n");
      phpCmd = 0;
    }
    {
      printf("3. query sensor status.\n");
      int status = peekSensor();
    }
    {
      memset(sendBuf, 0, strlen(sendBuf));
      memcpy(sendBuf, message, strlen(message));
      snd = sendto(sock, sendBuf, strlen(message), 0,
                   (struct sockaddr *)&client, structlength);
      if (snd < 0) {
        perror("sendto");
        exit(1);
      }
      printf("4. send OK!\n");
    }
  }
  close(sock);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
lea    0xe0e(%rip),%rax
mov    %rax,-0x50(%rbp)
movl   $0x22b8,-0x54(%rbp)
mov    0xe9c(%rip),%rax
mov    %rax,-0x1020(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x1018(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x1010(%rbp)
mov    0xe85(%rip),%al
mov    %al,-0x100e(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x50(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d39(%rip),%rax
mov    (%rax),%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    12e6 <main+0x106>
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x18,-0x44(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    132a <main+0x14a>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd19(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movl   $0x0,-0x1024(%rbp)
movl   $0x18,-0x44(%rbp)
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x830(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x7d0,%edx
xor    %ecx,%ecx
lea    -0x44(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    138e <main+0x1ae>
lea    0xcce(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    -0x830(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1040(%rbp)
lea    -0x1020(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1040(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x1030(%rbp)
lea    -0x830(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1038(%rbp),%rdi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
call   10a0 <memcpy@plt>
movl   $0x1,-0x1024(%rbp)
mov    $0x1,%eax
cmp    -0x1024(%rbp),%eax
jne    143d <main+0x25d>
lea    0xc37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1024(%rbp)
lea    0xc2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10d0 <peekSensor@plt>
mov    %eax,-0x1028(%rbp)
lea    -0x1000(%rbp),%rax
mov    %rax,-0x1068(%rbp)
lea    -0x1000(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1068(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    -0x1000(%rbp),%rax
mov    %rax,-0x1060(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1058(%rbp)
lea    -0x1020(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1060(%rbp),%rdi
mov    -0x1058(%rbp),%rsi
mov    %eax,%edx
call   10a0 <memcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x104c(%rbp)
lea    -0x1000(%rbp),%rax
mov    %rax,-0x1048(%rbp)
lea    -0x1020(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x104c(%rbp),%edi
mov    -0x1048(%rbp),%rsi
mov    %eax,%edx
lea    -0x38(%rbp),%r8
mov    -0x44(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1523 <main+0x343>
lea    0xb77(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xb68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1334 <main+0x154>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movl   $0xa203a,0x4f(%rsp)
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2dbb(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x38(%rsp)
lea    0xdc4(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x30(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %rax,0x28(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%rbx),%rax
mov    %rax,0x20(%rsp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %rax,0x10(%rsp)
mov    (%rbx),%rdi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
jns    12bb <main+0xcb>
lea    0xdd8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %eax,%r15d
lea    0x28(%rsp),%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jns    12ec <main+0xfc>
lea    0xd96(%rip),%rdi
call   1030 <puts@plt>
lea    0xd23(%rip),%rdi
jmp    1456 <main+0x266>
movl   $0x18,0xc(%rsp)
lea    0xd35(%rip),%rdi
call   1030 <puts@plt>
lea    0x60(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r15d,%edi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   10c0 <recvfrom@plt>
test   %eax,%eax
js     1435 <main+0x245>
lea    0x60(%rsp),%rbx
lea    0x40(%rsp),%rbp
lea    0x830(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xcc1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10b0 <memcpy@plt>
lea    0xcae(%rip),%rdi
call   1030 <puts@plt>
lea    0xcb0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10e0 <peekSensor@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   10b0 <memcpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%r9d
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   1090 <sendto@plt>
test   %eax,%eax
js     144f <main+0x25f>
lea    0xc69(%rip),%rdi
call   1030 <puts@plt>
movl   $0x18,0xc(%rsp)
lea    0xc20(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r13,%r9
call   10c0 <recvfrom@plt>
test   %eax,%eax
jns    1350 <main+0x160>
lea    0xbd3(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xbd3(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@__const.main.message = [19 x i8] c"I have received: \0A\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"socket create error!\0A\00"
@.str.2 = [20 x i8] c"socket bind error!\0A\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [16 x i8] c"waiting.......\0A\00"
@.str.5 = [9 x i8] c"recvfrom\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [17 x i8] c"1. received: %s\0A\00"
@.str.7 = [15 x i8] c"2. do command\0A\00"
@.str.8 = [25 x i8] c"3. query sensor status.\0A\00"
@.str.9 = [7 x i8] c"sendto\00"
@.str.10 = [13 x i8] c"4. send OK!\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [2000 x i8]
%10 = alloca [2000 x i8]
%11 = alloca [19 x i8]
%12 = alloca i32
%13 = alloca i32
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 8888, i32* %8
%14 = bitcast [19 x i8]* %11 to i8*
%15 = bitcast %struct.sockaddr_in* %2 to i8*
%16 = call i32 @memset(i8* %15, i32 0, i32 24)
%17 = load i8*, i8** @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i8* %17, i8** %18
%19 = load i8*, i8** %7
%20 = call i32 @inet_addr(i8* %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i8* @htons(i32 8888)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i8* %23, i8** %24
%25 = bitcast %struct.sockaddr_in* %3 to i8*
%26 = call i32 @memset(i8* %25, i32 0, i32 24)
%27 = load i8*, i8** @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %27, i8** %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = call i8* @htons(i32 8888)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i8* %33, i8** %34
%35 = load i8*, i8** @AF_INET
%36 = load i32, i32* @SOCK_DGRAM
%37 = call i32 @socket(i8* %35, i32 %36, i32 0)
store i32 %37, i32* %1
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %0
store i32 24, i32* %6
%43 = load i32, i32* %1
%44 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%45 = load i32, i32* %6
%46 = call i64 @bind(i32 %43, %struct.sockaddr* %44, i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %42
store i32 0, i32* %12
br label %53
53: ; preds = %52, %106
store i32 24, i32* %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* %1
%56 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%57 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%58 = call i32 @recvfrom(i32 %55, i8* %56, i32 2000, i32 0, %struct.sockaddr* %57, i32* %6)
store i32 %58, i32* %4
%59 = load i32, i32* %4
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %53
%62 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %53
%66 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %66)
%68 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%69 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
%71 = call i32 @memset(i8* %68, i32 0, i32 %70)
%72 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%73 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%74 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @memcpy(i8* %72, i8* %73, i32 %75)
store i32 1, i32* %12
br label %77
77: ; preds = %65
%78 = load i32, i32* %12
%79 = icmp eq i32 1, %78
br i1 %79, label %80, label %82
80: ; preds = %77
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %12
br label %82
82: ; preds = %80, %77
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
%84 = call i32 (...) @peekSensor()
store i32 %84, i32* %13
%85 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%86 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%87 = call i32 @strlen(i8* %86)
%88 = call i32 @memset(i8* %85, i32 0, i32 %87)
%89 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%90 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%91 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
%93 = call i32 @memcpy(i8* %89, i8* %90, i32 %92)
%94 = load i32, i32* %1
%95 = getelementptr inbounds [2000 x i8], [2000 x i8]* %10, i64 0, i64 0
%96 = getelementptr inbounds [19 x i8], [19 x i8]* %11, i64 0, i64 0
%97 = call i32 @strlen(i8* %96)
%98 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%99 = load i32, i32* %6
%100 = call i32 @sendto(i32 %94, i8* %95, i32 %97, i32 0, %struct.sockaddr* %98, i32 %99)
store i32 %100, i32* %5
%101 = load i32, i32* %5
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %82
%104 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %82
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %53
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@__const.main.message = [19 x i8] c"I have received: \0A\00"
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [5 x i8] c"bind\00"
@.str.5 = [9 x i8] c"recvfrom\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [17 x i8] c"1. received: %s\0A\00"
@.str.9 = [7 x i8] c"sendto\00"
@str = [15 x i8] c"waiting.......\00"
@str.11 = [14 x i8] c"2. do command\00"
@str.12 = [24 x i8] c"3. query sensor status.\00"
@str.13 = [12 x i8] c"4. send OK!\00"
@str.14 = [19 x i8] c"socket bind error!\00"
@str.15 = [21 x i8] c"socket create error!\00"
define void @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [2000 x i8]
%5 = alloca [2000 x i8]
%6 = alloca [19 x i8]
%7 = bitcast %struct.sockaddr_in* %1 to i8*
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [19 x i8], [19 x i8]* %6, i64 0, i64 0
%13 = call i32 @memset(i8* %7, i32 0, i32 24)
%14 = load i8*, i8** @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %14, i8** %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = call i8* @htons(i32 8888)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i8* %18, i8** %19
%20 = call i32 @memset(i8* %8, i32 0, i32 24)
%21 = load i8*, i8** @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i8* %21, i8** %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = call i8* @htons(i32 8888)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i8* %26, i8** %27
%28 = load i8*, i8** @AF_INET
%29 = load i32, i32* @SOCK_DGRAM
%30 = call i32 @socket(i8* %28, i32 %29, i32 0)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.15, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %0
%36 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%37 = call i64 @bind(i32 %30, %struct.sockaddr* %36, i32 24)
%38 = icmp slt i64 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %35
store i32 24, i32* %3
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%41 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%42 = call i32 @recvfrom(i32 %30, i8* %10, i32 2000, i32 0, %struct.sockaddr* %41, i32* %3)
%43 = icmp slt i32 %42, 0
br i1 %43, label %48, label %52
44: ; preds = %35
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %72, %39
%49 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %39, %72
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%54 = call i32 @strlen(i8* %12)
%55 = call i32 @memset(i8* %12, i32 0, i32 %54)
%56 = call i32 @strlen(i8* %10)
%57 = call i32 @memcpy(i8* %12, i8* %10, i32 %56)
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.11, i64 0, i64 0))
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.12, i64 0, i64 0))
%60 = call i32 (...) @peekSensor()
%61 = call i32 @strlen(i8* %11)
%62 = call i32 @memset(i8* %11, i32 0, i32 %61)
%63 = call i32 @strlen(i8* %12)
%64 = call i32 @memcpy(i8* %11, i8* %12, i32 %63)
%65 = call i32 @strlen(i8* %12)
%66 = load i32, i32* %3
%67 = call i32 @sendto(i32 %30, i8* %11, i32 %65, i32 0, %struct.sockaddr* %41, i32 %66)
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %52
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %52
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
store i32 24, i32* %3
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%75 = call i32 @recvfrom(i32 %30, i8* %10, i32 2000, i32 0, %struct.sockaddr* %41, i32* %3)
%76 = icmp slt i32 %75, 0
br i1 %76, label %48, label %52
}