#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 */

/* Type definitions */
typedef int /*<<< orphan*/ tv;
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ resp_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET6;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ append_node_id(void *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bzero(struct sockaddr_in6 *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *get_mem_for_raw_data();
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, void *, int /*<<< orphan*/, int /*<<< orphan*/,
             struct sockaddr *, int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct timeval *, int);
int /*<<< orphan*/ size_of_raw_data();
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
void *get_data_from_sensor(char *ip_addr, int port) {
  struct sockaddr_in6 serv_addr;
  socklen_t slen = sizeof(serv_addr);
  int sockfd;
  char dummy_msg[5] = "get\n";
  struct sockaddr_in6 resp_addr;
  socklen_t resp_addr_size = sizeof(resp_addr);
  ssize_t resp_buf_len;
  void *raw_buf;
  if ((sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) <= 0) {
    fprintf(stderr, "socket");
  }
  bzero(&serv_addr, sizeof(serv_addr));
  serv_addr.sin6_family = AF_INET6;
  serv_addr.sin6_port = htons(port);
  if (0 == inet_pton(AF_INET6, ip_addr, &serv_addr.sin6_addr)) {
    fprintf(stderr, "inet_aton() failed\n");
  }
  if (-1 == sendto(sockfd, dummy_msg, strlen(dummy_msg), 0,
                   (struct sockaddr *)&serv_addr, slen)) {
    printf("sendto() function");
  }
  raw_buf = get_mem_for_raw_data();
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 400000;
  if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
    perror("Error");
  }
  if (0 >= (resp_buf_len =
                recvfrom(sockfd, raw_buf, size_of_raw_data(), 0,
                         (struct sockaddr *)&resp_addr, &resp_addr_size))) {
    printf("recvfrom returned: %d\n", resp_buf_len);
    perror("Error");
  }
  append_node_id(raw_buf, &(serv_addr.sin6_addr));
  close(sockfd);
  return raw_buf;
}


x86 assembly (clang, -O0):
<get_data_from_sensor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    0xdf1(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xdec(%rip),%al
mov    %al,-0x21(%rbp)
movl   $0xc,-0x3c(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jg     1263 <get_data_from_sensor+0x73>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
call   10a0 <fprintf@plt>
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   10b0 <inet_pton@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12c1 <get_data_from_sensor+0xd1>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x25(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x25(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    130d <get_data_from_sensor+0x11d>
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1030 <get_mem_for_raw_data@plt>
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x61a80,-0x58(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2cb7(%rip),%rax
mov    (%rax),%esi
mov    0x2c8e(%rip),%rax
mov    (%rax),%edx
lea    -0x58(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    1361 <get_data_from_sensor+0x171>
lea    0xcd6(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   10e0 <size_of_raw_data@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,%ecx
mov    %ecx,-0x40(%rbp)
xor    %eax,%eax
cmp    %ecx,%eax
jl     13ba <get_data_from_sensor+0x1ca>
mov    -0x40(%rbp),%esi
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xc7d(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x48(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10d0 <append_node_id@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x48(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_data_from_sensor>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
movb   $0x0,0x8(%rsp)
movl   $0xa746567,0x4(%rsp)
0a
movl   $0xc,0xc(%rsp)
mov    0x2dba(%rip),%r12
mov    (%r12),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1254 <get_data_from_sensor+0x64>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xdb6(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10b0 <inet_pton@plt>
test   %rax,%rax
jne    12a3 <get_data_from_sensor+0xb3>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
call   10a0 <fprintf@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
jne    12dc <get_data_from_sensor+0xec>
lea    0xd4b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1030 <get_mem_for_raw_data@plt>
mov    %rax,%rbx
movq   $0x0,0x28(%rsp)
movl   $0x61a80,0x20(%rsp)
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
mov    0x2cc1(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
js     1367 <get_data_from_sensor+0x177>
xor    %eax,%eax
call   10e0 <size_of_raw_data@plt>
lea    0x30(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10c0 <recvfrom@plt>
test   %eax,%eax
jle    1375 <get_data_from_sensor+0x185>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10d0 <append_node_id@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %rbx,%rax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc4(%rip),%rdi
call   10f0 <perror@plt>
jmp    1320 <get_data_from_sensor+0x130>
lea    0xcbc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xca6(%rip),%rdi
call   10f0 <perror@plt>
jmp    1343 <get_data_from_sensor+0x153>

LLVM IR (-O0):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const.get_data_from_sensor.dummy_msg = [5 x i8] c"get\0A\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@stderr = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [20 x i8] c"inet_aton() failed\0A\00"
@.str.2 = [18 x i8] c"sendto() function\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.3 = [6 x i8] c"Error\00"
@.str.4 = [23 x i8] c"recvfrom returned: %d\0A\00"
define i8* @get_data_from_sensor(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in6
%6 = alloca i32
%7 = alloca i32
%8 = alloca [5 x i8]
%9 = alloca %struct.sockaddr_in6
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca %struct.timeval
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 12, i32* %6
%14 = bitcast [5 x i8]* %8 to i8*
store i32 12, i32* %10
%15 = load i32, i32* @AF_INET6
%16 = load i32, i32* @SOCK_DGRAM
%17 = load i32, i32* @IPPROTO_UDP
%18 = call i32 @socket(i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %7
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %2
%24 = call i32 @bzero(%struct.sockaddr_in6* %5, i32 12)
%25 = load i32, i32* @AF_INET6
%26 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* %4
%28 = call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 1
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET6
%31 = load i8*, i8** %3
%32 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 0
%33 = call i64 @inet_pton(i32 %30, i8* %31, i32* %32)
%34 = icmp eq i64 0, %33
br i1 %34, label %35, label %38
35: ; preds = %23
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %35, %23
%39 = load i32, i32* %7
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
%43 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%44 = load i32, i32* %6
%45 = call i32 @sendto(i32 %39, i8* %40, i32 %42, i32 0, %struct.sockaddr* %43, i32 %44)
%46 = icmp eq i32 -1, %45
br i1 %46, label %47, label %49
47: ; preds = %38
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %49
49: ; preds = %47, %38
%50 = call i8* (...) @get_mem_for_raw_data()
store i8* %50, i8** %12
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
store i64 0, i64* %51
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 400000, i32* %52
%53 = load i32, i32* %7
%54 = load i32, i32* @SOL_SOCKET
%55 = load i32, i32* @SO_RCVTIMEO
%56 = call i64 @setsockopt(i32 %53, i32 %54, i32 %55, %struct.timeval* %13, i32 16)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %49
%59 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %49
%61 = load i32, i32* %7
%62 = load i8*, i8** %12
%63 = call i32 (...) @size_of_raw_data()
%64 = bitcast %struct.sockaddr_in6* %9 to %struct.sockaddr*
%65 = call i32 @recvfrom(i32 %61, i8* %62, i32 %63, i32 0, %struct.sockaddr* %64, i32* %10)
store i32 %65, i32* %11
%66 = icmp sge i32 0, %65
br i1 %66, label %67, label %71
67: ; preds = %60
%68 = load i32, i32* %11
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %68)
%70 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %71
71: ; preds = %67, %60
%72 = load i8*, i8** %12
%73 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %5, i32 0, i32 0
%74 = call i32 @append_node_id(i8* %72, i32* %73)
%75 = load i32, i32* %7
%76 = call i32 @close(i32 %75)
%77 = load i8*, i8** %12
ret i8* %77
}

LLVM IR (-O2):
%struct.sockaddr_in6 = type { i32, i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const.get_data_from_sensor.dummy_msg = [5 x i8] c"get\0A\00"
@AF_INET6 = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@stderr = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [20 x i8] c"inet_aton() failed\0A\00"
@.str.2 = [18 x i8] c"sendto() function\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.3 = [6 x i8] c"Error\00"
@.str.4 = [23 x i8] c"recvfrom returned: %d\0A\00"
define i8* @get_data_from_sensor(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in6
%4 = alloca [5 x i8]
%5 = alloca %struct.sockaddr_in6
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = bitcast %struct.sockaddr_in6* %3 to i8*
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in6* %5 to i8*
%11 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%12 = load i32, i32* @AF_INET6
%13 = load i32, i32* @SOCK_DGRAM
%14 = load i32, i32* @IPPROTO_UDP
%15 = tail call i32 @socket(i32 %12, i32 %13, i32 %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %2
%21 = call i32 @bzero(%struct.sockaddr_in6* %3, i32 12)
%22 = load i32, i32* @AF_INET6
%23 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 %1)
%25 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET6
%27 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 0
%28 = call i64 @inet_pton(i32 %26, i8* %0, i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %20
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %30, %20
%34 = call i32 @strlen(i8* %9)
%35 = bitcast %struct.sockaddr_in6* %3 to %struct.sockaddr*
%36 = call i32 @sendto(i32 %15, i8* %9, i32 %34, i32 0, %struct.sockaddr* %35, i32 12)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = call i8* (...) @get_mem_for_raw_data()
%42 = bitcast %struct.timeval* %7 to i8*
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
store i64 0, i64* %43
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
store i32 400000, i32* %44
%45 = load i32, i32* @SOL_SOCKET
%46 = load i32, i32* @SO_RCVTIMEO
%47 = call i64 @setsockopt(i32 %15, i32 %45, i32 %46, %struct.timeval* %7, i32 16)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %40
%50 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %40
%52 = call i32 (...) @size_of_raw_data()
%53 = bitcast %struct.sockaddr_in6* %5 to %struct.sockaddr*
%54 = call i32 @recvfrom(i32 %15, i8* %41, i32 %52, i32 0, %struct.sockaddr* %53, i32* %6)
%55 = icmp slt i32 %54, 1
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %54)
%58 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %56, %51
%60 = call i32 @append_node_id(i8* %41, i32* %27)
%61 = call i32 @close(i32 %15)
ret i8* %41
}