#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 connect(int, struct sockaddr const *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int do_run() {
  int sockfd;
  int len;
  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(9876);
  len = sizeof(address);
  result = connect(sockfd, (const struct sockaddr *)&address, len);
  if (-1 == result)
    perror(NULL);
  while (1) {
    printf("send [%c]\n", ch);
    write(sockfd, &ch, 1);
    sleep(6);
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movb   $0x41,-0x1d(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe45(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x2694,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
movl   $0xc,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1080 <connect@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    1200 <do_run+0x80>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <perror@plt>
jmp    1205 <do_run+0x85>
lea    0xdfe(%rip),%rdi
movsbl -0x1d(%rbp),%esi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x6,%edi
call   1090 <sleep@plt>
jmp    1205 <do_run+0x85>

x86 assembly (clang, -O2):
<do_run>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movb   $0x41,0xf(%rsp)
mov    0x2e53(%rip),%r14
mov    (%r14),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
lea    0xe48(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x2694,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     1228 <do_run+0xa8>
lea    0xe1e(%rip),%r14
lea    0xf(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x41,%esi
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0x6,%edi
call   1090 <sleep@plt>
jmp    1200 <do_run+0x80>
xor    %edi,%edi
call   1070 <perror@plt>
jmp    11e5 <do_run+0x65>

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 = [11 x i8] c"send [%c]\0A\00"
define i32 @do_run() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i8
store i8 65, i8* %5
%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* %1
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %9, i32* %10
%11 = 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, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = call i32 @htons(i32 9876)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %14, i32* %15
store i32 12, i32* %2
%16 = load i32, i32* %1
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = load i32, i32* %2
%19 = call i32 @connect(i32 %16, %struct.sockaddr* %17, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp eq i32 -1, %20
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @perror(i32* null)
br label %24
24: ; preds = %22, %0
br label %25
25: ; preds = %24, %25
%26 = load i8, i8* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext %26)
%28 = load i32, i32* %1
%29 = call i32 @write(i32 %28, i8* %5, i32 1)
%30 = call i32 @sleep(i32 6)
br label %25
}

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 = [11 x i8] c"send [%c]\0A\00"
define i32 @do_run() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i8
%3 = bitcast %struct.sockaddr_in* %1 to i8*
store i8 65, i8* %2
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %7, i32* %8
%9 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 9876)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %11, i32* %12
%13 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%14 = call i32 @connect(i32 %6, %struct.sockaddr* %13, i32 12)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i32* null)
br label %18
18: ; preds = %16, %0
br label %19
19: ; preds = %18, %19
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext 65)
%21 = call i32 @write(i32 %6, i8* %2, i32 1)
%22 = call i32 @sleep(i32 6)
br label %19
}