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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, port, clientsize, n;
  char buf[9];
  struct sockaddr_in serv_addr, cli_addr;
  if (argc < 2) {
    fprintf(stderr, "ERROR, no port provided\n");
    exit(1);
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero((char *)&serv_addr, sizeof(serv_addr));
  port = atoi(argv[1]);
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(port);
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    error("ERROR on binding");
  }
  listen(sockfd, 5);
  clientsize = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clientsize);
  if (newsockfd < 0)
    error("ERROR on accept");
  bzero(buf, 9);
  n = read(newsockfd, buf, 9);
  int fd;
  fd = open("myfifo", O_WRONLY);
  write(fd, buf, strlen(buf) + 1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    122f <main+0x3f>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12b3 <main+0xc3>
lea    0xd6b(%rip),%rdi
call   10b0 <error@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12f0 <main+0x100>
lea    0xd3f(%rip),%rdi
call   10b0 <error@plt>
lea    -0x2d(%rbp),%rdi
mov    $0x9,%esi
call   10d0 <bzero@plt>
mov    -0x18(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x9,%edx
call   1070 <read@plt>
mov    %eax,-0x24(%rbp)
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
lea    0xd18(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x2d(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x2d(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x54(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x1,%edi
jle    1319 <main+0x129>
mov    %rsi,%r14
mov    0x2dda(%rip),%r12
mov    (%r12),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x8(%r14),%rdi
call   10f0 <atoi@plt>
mov    (%r12),%ecx
mov    %ecx,0x18(%rsp)
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
test   %rax,%rax
jns    127f <main+0x8f>
lea    0xd9f(%rip),%rdi
call   10b0 <error@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x28(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12b6 <main+0xc6>
lea    0xd79(%rip),%rdi
call   10b0 <error@plt>
lea    0x1f(%rsp),%r14
mov    %r14,%rdi
mov    $0x9,%esi
call   10d0 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x9,%edx
call   1070 <read@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%esi
lea    0xd53(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
lea    0xcd7(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERROR, no port provided\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"ERROR on binding\00"
@.str.2 = [16 x i8] c"ERROR on accept\00"
@.str.3 = [7 x i8] c"myfifo\00"
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [9 x i8]
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr_in
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = bitcast %struct.sockaddr_in* %12 to i8*
%26 = call i32 @bzero(i8* %25, i32 12)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* %8
%34 = call i32 @htons(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%41 = call i64 @bind(i32 %39, %struct.sockaddr* %40, i32 12)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %21
%44 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %21
%46 = load i32, i32* %6
%47 = call i32 @listen(i32 %46, i32 5)
store i32 12, i32* %9
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%50 = call i32 @accept(i32 %48, %struct.sockaddr* %49, i32* %9)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %45
%56 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%57 = call i32 @bzero(i8* %56, i32 9)
%58 = load i32, i32* %7
%59 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%60 = call i32 @read(i32 %58, i8* %59, i32 9)
store i32 %60, i32* %10
%61 = load i32, i32* @O_WRONLY
%62 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %61)
store i32 %62, i32* %14
%63 = load i32, i32* %14
%64 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%65 = getelementptr inbounds [9 x i8], [9 x i8]* %11, i64 0, i64 0
%66 = call i64 @strlen(i8* %65)
%67 = add nsw i64 %66, 1
%68 = call i32 @write(i32 %63, i8* %64, i64 %67)
%69 = load i32, i32* %14
%70 = call i32 @close(i32 %69)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [25 x i8] c"ERROR, no port provided\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [17 x i8] c"ERROR on binding\00"
@.str.2 = [16 x i8] c"ERROR on accept\00"
@.str.3 = [7 x i8] c"myfifo\00"
@O_WRONLY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [9 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = call i32 @bzero(i8* %9, i32 12)
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %24, i32* %25
%26 = tail call i32 @htons(i32 %23)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%31 = call i64 @bind(i32 %19, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %16
%34 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %16
%36 = call i32 @listen(i32 %19, i32 5)
store i32 12, i32* %3
%37 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%38 = call i32 @accept(i32 %19, %struct.sockaddr* %37, i32* %3)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
%43 = call i32 @bzero(i8* %8, i32 9)
%44 = call i32 @read(i32 %38, i8* %8, i32 9)
%45 = load i32, i32* @O_WRONLY
%46 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = call i64 @strlen(i8* %8)
%48 = add nsw i64 %47, 1
%49 = call i32 @write(i32 %46, i8* %8, i64 %48)
%50 = call i32 @close(i32 %46)
ret i32 0
}