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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(void *, int);
int /*<<< orphan*/ close(int);
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int main() {
  int sockfd, n;
  struct sockaddr_in servaddr;
  char recvline[100], ip[100];
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero((void *)&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  servaddr.sin_port = htons(5555);
  for (;;) {
    scanf("%s", ip);
    if (feof(stdin))
      break;
    sendto(sockfd, ip, strlen(ip), 0, (struct sockaddr *)&servaddr,
           sizeof(servaddr));
    n = recvfrom(sockfd, recvline, 100, 0, NULL, NULL);
    recvline[n] = 0;
    printf("%s", recvline);
  }
  close(sockfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe01(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x15b3,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
lea    -0xf0(%rbp),%rsi
lea    0xde8(%rip),%rdi
call   10b0 <scanf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     1244 <main+0x94>
jmp    12c3 <main+0x113>
mov    -0x8(%rbp),%eax
mov    %eax,-0xfc(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xf0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xfc(%rbp),%edi
mov    -0xf8(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10a0 <recvfrom@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd51(%rip),%rdi
call   1050 <printf@plt>
jmp    1214 <main+0x64>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    0x2e20(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe0a(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x15b3,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
lea    0xdf7(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0x2dbc(%rip),%r13
mov    0x0(%r13),%edi
call   1090 <feof@plt>
test   %rax,%rax
jne    12b4 <main+0x104>
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
lea    0x80(%rsp),%r15
lea    0xdbd(%rip),%r12
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
cltq
movb   $0x0,0x80(%rsp,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    0x0(%r13),%edi
call   1090 <feof@plt>
test   %rax,%rax
je     1250 <main+0xa0>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0xe8,%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
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [3 x i8] c"%s\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [100 x i8]
%6 = alloca [100 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = call i32 @bzero(i8* %10, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %12, i32* %13
%14 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = call i32 @htons(i32 5555)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %17, i32* %18
br label %19
19: ; preds = %26, %0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @stdin
%23 = call i64 @feof(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
br label %41
26: ; preds = %19
%27 = load i32, i32* %2
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i32 @sendto(i32 %27, i8* %28, i32 %30, i32 0, %struct.sockaddr* %31, i32 12)
%33 = load i32, i32* %2
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%35 = call i32 @recvfrom(i32 %33, i8* %34, i32 100, i32 0, i32* null, i32* null)
store i32 %35, i32* %3
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %19
41: ; preds = %25
%42 = load i32, i32* %2
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %1
ret i32 %44
}

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
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [3 x i8] c"%s\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = call i32 @bzero(i8* %4, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 5555)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %15, i32* %16
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%18 = load i32, i32* @stdin
%19 = call i64 @feof(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %0
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %23
23: ; preds = %21, %23
%24 = call i32 @strlen(i8* %6)
%25 = call i32 @sendto(i32 %9, i8* %6, i32 %24, i32 0, %struct.sockaddr* %22, i32 12)
%26 = call i32 @recvfrom(i32 %9, i8* %5, i32 100, i32 0, i32* null, i32* null)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%31 = load i32, i32* @stdin
%32 = call i64 @feof(i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %23, label %34
34: ; preds = %23, %0
%35 = call i32 @close(i32 %9)
ret i32 0
}