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

/* Type definitions */
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ MSG_OOB;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int fd;
  char buf[1024] = {};
  struct sockaddr_in addr;
  if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day13/oob_s.c",
              24, "socket", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(9999);
  inet_aton("127.0.0.1", &addr.sin_addr);
  if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day13/oob_s.c",
              30, "connect", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  while (1) {
    send(fd, "hehe", 4, MSG_OOB);
    memset(buf, 0x00, sizeof(buf));
    sleep(1);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1242 <main+0xa2>
jmp    11ef <main+0x4f>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x424(%rbp),%edi
mov    %rax,%r9
lea    0xde4(%rip),%rsi
lea    0xded(%rip),%rdx
mov    $0x18,%ecx
lea    0xe75(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    $0x270f,%edi
call   1030 <htons@plt>
mov    %eax,-0x41c(%rbp)
lea    -0x420(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1070 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    12e9 <main+0x149>
jmp    1296 <main+0xf6>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x428(%rbp),%edi
mov    %rax,%r9
lea    0xd3d(%rip),%rsi
lea    0xd46(%rip),%rdx
mov    $0x1e,%ecx
lea    0xddf(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    12ee <main+0x14e>
mov    -0x8(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%ecx
lea    0xdbc(%rip),%rsi
mov    $0x4,%edx
call   1040 <send@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    12ee <main+0x14e>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     126e <main+0xce>
mov    %eax,%ebx
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0x270f,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xea6(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1070 <inet_aton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     12a3 <main+0x103>
mov    0x2db1(%rip),%r12
lea    0xe87(%rip),%r14
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12),%ecx
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <send@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    1240 <main+0xa0>
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebx
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd74(%rip),%rsi
lea    0xd7d(%rip),%rdx
lea    0xe0a(%rip),%r8
mov    %ebx,%edi
mov    $0x18,%ecx
jmp    12d6 <main+0x136>
mov    0x2d26(%rip),%rax
mov    (%rax),%ebx
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd3f(%rip),%rsi
lea    0xd48(%rip),%rdx
lea    0xde6(%rip),%r8
mov    %ebx,%edi
mov    $0x1e,%ecx
mov    %rax,%r9
call   1060 <fprintf@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day13/oob_s.c\00"
@.str.2 = [7 x i8] c"socket\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [5 x i8] c"hehe\00"
@MSG_OOB = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%5 = bitcast [1024 x i8]* %3 to i8*
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %19
10: ; preds = %0
br label %11
11: ; preds = %10
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %0
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 9999)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%25 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %24)
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%28 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %39
30: ; preds = %19
br label %31
31: ; preds = %30
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %19
br label %40
40: ; preds = %39, %40
%41 = load i32, i32* %2
%42 = load i32, i32* @MSG_OOB
%43 = call i32 @send(i32 %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4, i32 %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%45 = call i32 @memset(i8* %44, i32 0, i32 1024)
%46 = call i32 @sleep(i32 1)
br label %40
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day13/oob_s.c\00"
@.str.2 = [7 x i8] c"socket\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [5 x i8] c"hehe\00"
@MSG_OOB = global i32 0
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 9999)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%22 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %21)
%23 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%24 = call i32 @connect(i32 %7, %struct.sockaddr* %23, i32 12)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %33
26: ; preds = %16
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %16, %33
%34 = load i32, i32* @MSG_OOB
%35 = call i32 @send(i32 %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4, i32 %34)
%36 = call i32 @memset(i8* %3, i32 0, i32 1024)
%37 = call i32 @sleep(i32 1)
br label %33
}