#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_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, scalar_t__, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
main() {
  int sockfd;
  struct sockaddr_in serv_addr;
  int i;
  char buf[100];
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("Unable to create socket\n");
    exit(0);
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  serv_addr.sin_port = htons(6000);
  if ((connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) < 0) {
    printf("Unable to connect to server\n");
    exit(0);
  }
  for (i = 0; i < 100; i++)
    buf[i] = '\0';
  recv(sockfd, buf, 100, 0);
  printf("%s\n", buf);
  printf("Enter a valid expression\n");
  scanf("%s", buf);
  send(sockfd, buf, strlen(buf) + 1, 0);
  for (i = 0; i < 100; i++)
    buf[i] = '\0';
  recv(sockfd, buf, 100, 0);
  printf("The value of expression is %s\n", buf);
  close(sockfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%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)
cmp    $0x0,%eax
jge    11fc <main+0x4c>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe0a(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1770,%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    1254 <main+0xa4>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    127c <main+0xcc>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125b <main+0xab>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x80(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xda0(%rip),%rdi
call   10a0 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    131f <main+0x16f>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12fe <main+0x14e>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x80(%rbp),%rsi
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e1a(%rip),%r14
mov    (%r14),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12fd <main+0x13d>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
lea    0xe07(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1770,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     1306 <main+0x146>
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xdb7(%rip),%rdi
call   1040 <puts@plt>
lea    0xd89(%rip),%rdi
mov    %r14,%rsi
call   10b0 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1070 <send@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movl   $0x0,0x70(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd2b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd5d(%rip),%rdi
jmp    130d <main+0x14d>
lea    0xd38(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

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_STREAM = global i32 0
@.str = [25 x i8] c"Unable to create socket\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [29 x i8] c"Unable to connect to server\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [26 x i8] c"Enter a valid expression\0A\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [31 x i8] c"The value of expression is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [100 x i8]
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, 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 6000)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i64 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %13
store i32 0, i32* %4
br label %29
29: ; preds = %36, %28
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 100
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %34
store i8 0, i8* %35
br label %36
36: ; preds = %32
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %29
39: ; preds = %29
%40 = load i32, i32* %2
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%42 = call i32 @recv(i32 %40, i8* %41, i32 100, i32 0)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = load i32, i32* %2
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%51 = call i64 @strlen(i8* %50)
%52 = add nsw i64 %51, 1
%53 = call i32 @send(i32 %48, i8* %49, i64 %52, i32 0)
store i32 0, i32* %4
br label %54
54: ; preds = %61, %39
%55 = load i32, i32* %4
%56 = icmp slt i32 %55, 100
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %59
store i8 0, i8* %60
br label %61
61: ; preds = %57
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 1
store i32 %63, i32* %4
br label %54
64: ; preds = %54
%65 = load i32, i32* %2
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%67 = call i32 @recv(i32 %65, i8* %66, i32 100, i32 0)
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %68)
%70 = load i32, i32* %2
%71 = call i32 @close(i32 %70)
%72 = load i32, i32* %1
ret i32 %72
}

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_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [31 x i8] c"The value of expression is %s\0A\00"
@str = [25 x i8] c"Enter a valid expression\00"
@str.7 = [28 x i8] c"Unable to connect to server\00"
@str.8 = [24 x i8] c"Unable to create socket\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, 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 = tail call i32 @htons(i32 6000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i64 @connect(i32 %8, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %13
%24 = call i32 @recv(i32 %8, i8* %5, i32 100, i32 0)
%25 = call i32 @puts(i8* %5)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%28 = call i64 @strlen(i8* %5)
%29 = add nsw i64 %28, 1
%30 = call i32 @send(i32 %8, i8* %5, i64 %29, i32 0)
%31 = call i32 @recv(i32 %8, i8* %5, i32 100, i32 0)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%33 = call i32 @close(i32 %8)
ret i32 0
34: ; preds = %13
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
%36 = call i32 @exit(i32 0)
unreachable
}