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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
char getchar();
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int sockfd;
  struct sockaddr_in address;
  while (1) {
    printf("Input a char: ");
    char ch;
    do {
      ch = getchar();
    } while (ch == '\n');
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1) {
      perror("socket failed");
      return -1;
    }
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = inet_addr("127.0.0.1");
    address.sin_port = 9437;
    int res = connect(sockfd, (struct sockaddr *)&address, sizeof(address));
    if (res == -1) {
      perror("Oops client1");
      return -1;
    }
    write(sockfd, &ch, 1);
    read(sockfd, &ch, 1);
    printf("char from server - %c\n", ch);
    close(sockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
je     11ad <main+0x1d>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1202 <main+0x72>
lea    0xe1e(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <main+0x10b>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe08(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
movl   $0x24dd,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    125a <main+0xca>
lea    0xdde(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129b <main+0x10b>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0x19(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
jmp    119f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e43(%rip),%r15
lea    0xe71(%rip),%r12
lea    0x8(%rsp),%r13
lea    0x7(%rsp),%rbx
lea    0xe77(%rip),%rbp
nopl   (%rax)
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0xa,%al
je     11d0 <main+0x40>
mov    %al,0x7(%rsp)
mov    (%r15),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1266 <main+0xd6>
mov    %eax,%r14d
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %r12,%rdi
call   1070 <inet_addr@plt>
mov    %eax,0xc(%rsp)
movl   $0x24dd,0x8(%rsp)
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     126f <main+0xdf>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl 0x7(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
jmp    11c0 <main+0x30>
lea    0xda2(%rip),%rdi
jmp    1276 <main+0xe6>
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%eax
add    $0x18,%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 }
@.str = [15 x i8] c"Input a char: \00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"socket failed\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [13 x i8] c"Oops client1\00"
@.str.4 = [23 x i8] c"char from server - %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %0, %36
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %10, %6
%9 = call signext i8 (...) @getchar()
store i8 %9, i8* %4
br label %10
10: ; preds = %8
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %8, label %14
14: ; preds = %10
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
22: ; preds = %14
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 9437, i32* %28
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 12)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
36: ; preds = %22
%37 = load i32, i32* %2
%38 = call i32 @write(i32 %37, i8* %4, i32 1)
%39 = load i32, i32* %2
%40 = call i32 @read(i32 %39, i8* %4, i32 1)
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %2
%45 = call i32 @close(i32 %44)
br label %6
46: ; preds = %34, %20
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"Input a char: \00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [14 x i8] c"socket failed\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [13 x i8] c"Oops client1\00"
@.str.4 = [23 x i8] c"char from server - %c\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i8
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%7 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %8
8: ; preds = %23, %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %10, %8
%11 = call signext i8 (...) @getchar()
%12 = icmp eq i8 %11, 10
br i1 %12, label %10, label %13
13: ; preds = %10
store i8 %11, i8* %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %30, label %18
18: ; preds = %13
%19 = load i32, i32* @AF_INET
store i32 %19, i32* %4
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 %20, i32* %5
store i32 9437, i32* %6
%21 = call i32 @connect(i32 %16, %struct.sockaddr* %7, i32 12)
%22 = icmp eq i32 %21, -1
br i1 %22, label %30, label %23
23: ; preds = %18
%24 = call i32 @write(i32 %16, i8* %2, i32 1)
%25 = call i32 @read(i32 %16, i8* %2, i32 1)
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = call i32 @close(i32 %16)
br label %8
30: ; preds = %18, %13
%31 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), %18 ]
%32 = call i32 @perror(i8* %31)
ret i32 -1
}