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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd = -1;
  int len = 0;
  struct sockaddr_in address;
  int result;
  char ch = 'A';
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = inet_addr("127.0.0.1");
  address.sin_port = htons(9736);
  len = sizeof(address);
  result = connect(sockfd, (struct sockaddr *)&address, len);
  if (result == -1) {
    perror("ops:client\n");
    exit(1);
  } else {
    write(sockfd, &ch, 1);
    read(sockfd, &ch, 1);
    printf("char from server = %c\n", ch);
    close(sockfd);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x41,-0x2d(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xe09(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x2608,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10b0 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1245 <main+0xa5>
lea    0xdd4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
lea    0xda8(%rip),%rdi
movsbl -0x2d(%rbp),%esi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movb   $0x41,0x7(%rsp)
mov    0x2e35(%rip),%r14
mov    (%r14),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
lea    0xe2a(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0x2608,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1219 <main+0x79>
lea    0xe00(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0x7(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%esi
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <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 = [10 x i8] c"127.0.0.1\00"
@.str.1 = [12 x i8] c"ops:client\0A\00"
@.str.2 = [23 x i8] c"char from server = %c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 0, i32* %7
store i8 65, i8* %10
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, 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 9736)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %19, i32* %20
store i32 12, i32* %7
%21 = load i32, i32* %6
%22 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%23 = load i32, i32* %7
%24 = call i32 @connect(i32 %21, %struct.sockaddr* %22, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %2
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
%31 = load i32, i32* %6
%32 = call i32 @write(i32 %31, i8* %10, i32 1)
%33 = load i32, i32* %6
%34 = call i32 @read(i32 %33, i8* %10, i32 1)
%35 = load i8, i8* %10
%36 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %35)
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
%39 = call i32 @exit(i32 0)
unreachable
}

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 = [10 x i8] c"127.0.0.1\00"
@.str.1 = [12 x i8] c"ops:client\0A\00"
@.str.2 = [23 x i8] c"char from server = %c\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i8
%5 = bitcast %struct.sockaddr_in* %3 to i8*
store i8 65, i8* %4
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %9, i32* %10
%11 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 9736)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%16 = call i32 @connect(i32 %8, %struct.sockaddr* %15, i32 12)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 @write(i32 %8, i8* %4, i32 1)
%23 = call i32 @read(i32 %8, i8* %4, i32 1)
%24 = load i8, i8* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8 signext %24)
%26 = call i32 @close(i32 %8)
%27 = call i32 @exit(i32 0)
unreachable
}