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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
scalar_t__ connect(int, struct sockaddr *, int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(void) {
  int sockfd = 0;
  struct sockaddr_in serv_addr;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("\n Error : Could not create socket \n");
    return 1;
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(5000);
  serv_addr.sin_addr.s_addr = inet_addr("10.1.2.25");
  bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    printf("\n Error : Connect Failed \n");
    return 1;
  }
  FILE *fp = fopen("log-w-date.txt", "rb");
  if (fp == NULL) {
    printf("File opern error");
    return 1;
  }
  while (1) {
    unsigned char buff[256] = {0};
    int nread = fread(buff, 1, 256, fp);
    printf("Bytes read %d \n", nread);
    if (nread > 0) {
      printf("Sending \n");
      write(sockfd, buff, nread);
    }
    if (nread < 256) {
      if (feof(fp))
        printf("End of file\n");
      if (ferror(fp))
        printf("Error reading\n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1218 <main+0x58>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139a <main+0x1da>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1388,%edi
call   1060 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xdec(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    1286 <main+0xc6>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139a <main+0x1da>
lea    0xdbc(%rip),%rdi
lea    0xdc4(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12c2 <main+0x102>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139a <main+0x1da>
jmp    12c7 <main+0x107>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1040 <fread@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%esi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x124(%rbp)
jle    133e <main+0x17e>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1050 <write@plt>
cmpl   $0x100,-0x124(%rbp)
jge    1395 <main+0x1d5>
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     136f <main+0x1af>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1390 <main+0x1d0>
lea    0xd0a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    139a <main+0x1da>
jmp    12c7 <main+0x107>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     140f <main+0x24f>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x1388,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xdef(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     141d <main+0x25d>
lea    0xdc0(%rip),%rdi
lea    0xdc8(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     142b <main+0x26b>
mov    %rax,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
lea    0xd3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %ebp,%ebp
jle    13d9 <main+0x219>
lea    0xd4f(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xd19(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1060 <write@plt>
cmp    $0xff,%ebp
jbe    13d9 <main+0x219>
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
test   %ebp,%ebp
jg     1320 <main+0x160>
mov    %r14,%rdi
call   10a0 <feof@plt>
test   %rax,%rax
je     13f2 <main+0x232>
lea    0xc5e(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     140b <main+0x24b>
lea    0xc37(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    143e <main+0x27e>
lea    0xc64(%rip),%rdi
call   1030 <puts@plt>
jmp    1439 <main+0x279>
lea    0xc3c(%rip),%rdi
call   1030 <puts@plt>
jmp    1439 <main+0x279>
lea    0xbea(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [36 x i8] c"\0A Error : Could not create socket \0A\00"
@.str.1 = [10 x i8] c"10.1.2.25\00"
@.str.2 = [27 x i8] c"\0A Error : Connect Failed \0A\00"
@.str.3 = [15 x i8] c"log-w-date.txt\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [17 x i8] c"File opern error\00"
@.str.6 = [16 x i8] c"Bytes read %d \0A\00"
@.str.7 = [10 x i8] c"Sending \0A\00"
@.str.8 = [13 x i8] c"End of file\0A\00"
@.str.9 = [15 x i8] c"Error reading\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %69
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 @htons(i32 5000)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i64 @connect(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %13
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %69
30: ; preds = %13
%31 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %31, i32** %4
%32 = load i32*, i32** %4
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %69
36: ; preds = %30
br label %37
37: ; preds = %36, %68
%38 = bitcast [256 x i8]* %5 to i8*
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%40 = load i32*, i32** %4
%41 = call i32 @fread(i8* %39, i32 1, i32 256, i32* %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %6
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %37
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%48 = load i32, i32* %2
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%50 = load i32, i32* %6
%51 = call i32 @write(i32 %48, i8* %49, i32 %50)
br label %52
52: ; preds = %46, %37
%53 = load i32, i32* %6
%54 = icmp slt i32 %53, 256
br i1 %54, label %55, label %68
55: ; preds = %52
%56 = load i32*, i32** %4
%57 = call i64 @feof(i32* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
br label %61
61: ; preds = %59, %55
%62 = load i32*, i32** %4
%63 = call i64 @ferror(i32* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
br label %69
68: ; preds = %52
br label %37
69: ; preds = %11, %28, %34, %67
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, 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"10.1.2.25\00"
@.str.3 = [15 x i8] c"log-w-date.txt\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [17 x i8] c"File opern error\00"
@.str.6 = [16 x i8] c"Bytes read %d \0A\00"
@str = [14 x i8] c"Error reading\00"
@str.10 = [12 x i8] c"End of file\00"
@str.11 = [9 x i8] c"Sending \00"
@str.12 = [26 x i8] c"\0A Error : Connect Failed \00"
@str.13 = [35 x i8] c"\0A Error : Could not create socket \00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [256 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.13, i64 0, i64 0))
br label %53
10: ; preds = %0
%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 @htons(i32 5000)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %13, i32* %14
%15 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%18 = call i32 @bind(i32 %6, %struct.sockaddr* %17, i32 12)
%19 = call i64 @connect(i32 %6, %struct.sockaddr* %17, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %10
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
br label %53
23: ; preds = %10
%24 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%28 = call i32 @fread(i8* %27, i32 1, i32 256, i32* %24)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = icmp sgt i32 %28, 0
br i1 %30, label %33, label %38
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %53
33: ; preds = %26, %49
%34 = phi i32 [ %50, %49 ], [ %28, %26 ]
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.11, i64 0, i64 0))
%36 = call i32 @write(i32 %6, i8* %27, i32 %34)
%37 = icmp ult i32 %34, 256
br i1 %37, label %38, label %49
38: ; preds = %33, %49, %26
%39 = call i64 @feof(i32* %24)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = call i64 @ferror(i32* %24)
%45 = icmp eq i64 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
br label %53
49: ; preds = %33
%50 = call i32 @fread(i8* %27, i32 1, i32 256, i32* %24)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %50)
%52 = icmp sgt i32 %50, 0
br i1 %52, label %33, label %38
53: ; preds = %48, %31, %21, %8
%54 = phi i32 [ 1, %8 ], [ 1, %21 ], [ 1, %31 ], [ 0, %48 ]
ret i32 %54
}