#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 /*<<< orphan*/ serv;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  struct sockaddr_in serv;
  char buff[150];
  int sockfd, n;
  if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
    err_sys("socket error");
  memset(&serv, 0, sizeof(serv));
  serv.sin_family = AF_INET;
  serv.sin_addr.s_addr = inet_addr("192.168.2.104");
  serv.sin_port = htons(13);
  if (sendto(sockfd, buff, 150, 0, (struct sockaddr *)&serv, sizeof(serv)) !=
      150)
    err_sys("sendto error");
  if ((n = recvfrom(sockfd, buff, 150, 0, (struct sockaddr *)NULL,
                    (int *)NULL)) < 2)
    err_sys("recvfrom error");
  buff[n - 2] = 0;
  printf("%s\n", buff);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0xb4(%rbp)
cmp    $0x0,%eax
jge    11c6 <main+0x46>
lea    0xe3f(%rip),%rdi
call   1030 <err_sys@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    0xe24(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0xc(%rbp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0xb4(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0x10(%rbp),%r8
mov    $0x96,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0x96,%eax
je     1238 <main+0xb8>
lea    0xde8(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0xb4(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x96,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom@plt>
mov    %eax,-0xb8(%rbp)
cmp    $0x2,%eax
jge    1274 <main+0xf4>
lea    0xdb9(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0xb8(%rbp),%eax
sub    $0x2,%eax
cltq
movb   $0x0,-0xb0(%rbp,%rax,1)
lea    -0xb0(%rbp),%rsi
lea    0xda2(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11b5 <main+0x35>
lea    0xe50(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe32(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0xd,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x96,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0x96,%eax
je     1220 <main+0xa0>
lea    0xe00(%rip),%rdi
call   1030 <err_sys@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x96,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1090 <recvfrom@plt>
mov    %eax,%ebx
cmp    $0x1,%eax
jg     124f <main+0xcf>
lea    0xdde(%rip),%rdi
call   1030 <err_sys@plt>
movslq %ebx,%rax
movb   $0x0,-0x2(%rax,%r14,1)
lea    0xdd8(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@AF_INET = global i32 0
@.str.1 = [14 x i8] c"192.168.2.104\00"
@.str.2 = [13 x i8] c"sendto error\00"
@.str.3 = [15 x i8] c"recvfrom error\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca [150 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 13)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %4
%22 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%23 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%24 = call i32 @sendto(i32 %21, i8* %22, i32 150, i32 0, %struct.sockaddr* %23, i32 12)
%25 = icmp ne i32 %24, 150
br i1 %25, label %26, label %28
26: ; preds = %12
%27 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %12
%29 = load i32, i32* %4
%30 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%31 = call i32 @recvfrom(i32 %29, i8* %30, i32 150, i32 0, %struct.sockaddr* null, i32* null)
store i32 %31, i32* %5
%32 = icmp slt i32 %31, 2
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @err_sys(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %28
%36 = load i32, i32* %5
%37 = sub nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %40)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [13 x i8] c"socket error\00"
@AF_INET = global i32 0
@.str.1 = [14 x i8] c"192.168.2.104\00"
@.str.2 = [13 x i8] c"sendto error\00"
@.str.3 = [15 x i8] c"recvfrom error\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [150 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = call i32 @htons(i32 13)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%20 = call i32 @sendto(i32 %7, i8* %4, i32 150, i32 0, %struct.sockaddr* %19, i32 12)
%21 = icmp eq i32 %20, 150
br i1 %21, label %24, label %22
22: ; preds = %11
%23 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %11
%25 = call i32 @recvfrom(i32 %7, i8* %4, i32 150, i32 0, %struct.sockaddr* null, i32* null)
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @err_sys(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = add nsw i32 %25, -2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
ret i32 0
}