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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ netclose(int);
int netopen(char *, int /*<<< orphan*/);
int /*<<< orphan*/ netread(int, char *, int);
int /*<<< orphan*/ netserverinit(char *, double);
int /*<<< orphan*/ netwrite(int, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  char res[512];
  char random[512];
  int bsfd = open("/home/carlin/Documents/bs.txt", O_RDWR);
  int result = read(bsfd, random, 4);
  write(bsfd, "lol", 100);
  printf("%s\n", random);
  netserverinit("localhost", 0.5);
  int fd = netopen("/home/carlin/Documents/bs.txt", O_RDWR);
  netread(fd, res, 4);
  netwrite(fd, random, 16);
  netclose(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe4f(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x4,%edx
call   1090 <read@plt>
mov    %eax,-0x418(%rbp)
mov    -0x414(%rbp),%edi
lea    0xe38(%rip),%rsi
mov    $0x64,%edx
call   1030 <write@plt>
lea    -0x410(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1070 <printf@plt>
lea    0xe1c(%rip),%rdi
movsd  0xde6(%rip),%xmm0
call   1050 <netserverinit@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    0xdd9(%rip),%rdi
call   1080 <netopen@plt>
mov    %eax,-0x41c(%rbp)
mov    -0x41c(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x4,%edx
call   1040 <netread@plt>
mov    -0x41c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <netwrite@plt>
mov    -0x41c(%rbp),%edi
call   1060 <netclose@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    0x2e44(%rip),%r15
mov    (%r15),%esi
lea    0xe5a(%rip),%r14
mov    %r14,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1090 <read@plt>
lea    0xe55(%rip),%rsi
mov    %ebp,%edi
mov    $0x64,%edx
call   1030 <write@plt>
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
lea    0xe3b(%rip),%rdi
movsd  0xe05(%rip),%xmm0
call   1050 <netserverinit@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1080 <netopen@plt>
mov    %eax,%ebp
lea    0x200(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <netread@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
call   10b0 <netwrite@plt>
mov    %ebp,%edi
call   1060 <netclose@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/home/carlin/Documents/bs.txt\00"
@O_RDWR = global i32 0
@.str.1 = [4 x i8] c"lol\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [10 x i8] c"localhost\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 4)
store i32 %15, i32* %9
%16 = load i32, i32* %8
%17 = call i32 @write(i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 100)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 @netserverinit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double 5.000000e-01)
%21 = load i32, i32* @O_RDWR
%22 = call i32 @netopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = call i32 @netread(i32 %23, i8* %24, i32 4)
%26 = load i32, i32* %10
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%28 = call i32 @netwrite(i32 %26, i8* %27, i32 16)
%29 = load i32, i32* %10
%30 = call i32 @netclose(i32 %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"/home/carlin/Documents/bs.txt\00"
@O_RDWR = global i32 0
@.str.1 = [4 x i8] c"lol\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [10 x i8] c"localhost\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @read(i32 %8, i8* %6, i32 4)
%10 = tail call i32 @write(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 100)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%12 = call i32 @netserverinit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double 5.000000e-01)
%13 = load i32, i32* @O_RDWR
%14 = call i32 @netopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @netread(i32 %14, i8* %5, i32 4)
%16 = call i32 @netwrite(i32 %14, i8* %6, i32 16)
%17 = call i32 @netclose(i32 %14)
ret i32 0
}