#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 hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ hostname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
char EOF;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr_in *, int *);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ htons(unsigned short);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
main() {
  unsigned short int port = 1234;
  char c;
  FILE *fp;
  int fromlen;
  char hostname[64];
  struct hostent *hp;
  struct sockaddr_in sin, fsin;
  register int i, s, ns;
  gethostname(hostname, sizeof(hostname));
  if ((hp = gethostbyname(hostname)) == NULL) {
    fprintf(stderr, "%s: host unknown.\n", hostname);
    exit(1);
  }
  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("server: socket");
    exit(1);
  }
  sin.sin_family = AF_INET;
  sin.sin_port = htons(port);
  bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
  if (bind(s, &sin, sizeof(sin)) < 0) {
    perror("server: bind");
    exit(1);
  }
  while (1) {
    if (listen(s, 5) < 0) {
      perror("server: listen");
      exit(1);
    }
    if ((ns = accept(s, &fsin, &fromlen)) < 0) {
      perror("server: accept");
      exit(1);
    }
    fp = fdopen(ns, "r");
    while ((c = fgetc(fp)) != EOF) {
      if (c == '^')
        break;
      putchar(c);
      fflush(NULL);
    }
  }
  close(s);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movw   $0x4d2,-0x6(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   10f0 <gethostname@plt>
lea    -0x60(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    1250 <main+0x60>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xdbf(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x90(%rbp)
cmp    $0x0,%eax
jge    128e <main+0x9e>
lea    0xd94(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
movzwl -0x6(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x74(%rbp)
mov    -0x68(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x78(%rbp),%rsi
mov    -0x68(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    -0x90(%rbp),%edi
lea    -0x78(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    12f0 <main+0x100>
lea    0xd41(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    12f5 <main+0x105>
mov    -0x90(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
jge    1325 <main+0x135>
lea    0xd19(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x90(%rbp),%edi
lea    -0x88(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jge    1360 <main+0x170>
lea    0xced(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x94(%rbp),%edi
lea    0xce0(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x7(%rbp)
movsbl %al,%eax
mov    0x2c54(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     13c0 <main+0x1d0>
movsbl -0x7(%rbp),%eax
cmp    $0x5e,%eax
jne    13a9 <main+0x1b9>
jmp    13c0 <main+0x1d0>
movsbl -0x7(%rbp),%edi
call   1030 <putchar@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
jmp    1376 <main+0x186>
jmp    12f5 <main+0x105>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   10f0 <gethostname@plt>
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
jne    1241 <main+0x51>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %rax,%rbx
mov    0x2d9d(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
jns    126e <main+0x7e>
lea    0xdaa(%rip),%rdi
jmp    1359 <main+0x169>
mov    %eax,%r13d
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x4d2,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10b0 <bcopy@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    12b7 <main+0xc7>
lea    0xd70(%rip),%rdi
jmp    1359 <main+0x169>
mov    %r13d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %rax,%rax
jns    12d5 <main+0xe5>
lea    0xd5f(%rip),%rdi
jmp    1359 <main+0x169>
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xd67(%rip),%r12
mov    0x2cf3(%rip),%rbp
jmp    1302 <main+0x112>
nop
mov    %r13d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %rax,%rax
js     12c9 <main+0xd9>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10e0 <accept@plt>
test   %eax,%eax
js     1352 <main+0x162>
mov    %eax,%edi
mov    %r12,%rsi
call   10a0 <fdopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1050 <fgetc@plt>
cmp    $0x5e,%al
je     12f0 <main+0x100>
cmp    0x0(%rbp),%al
je     12f0 <main+0x100>
movsbl %al,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    %rbx,%rdi
jmp    1330 <main+0x140>
lea    0xce5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"%s: host unknown.\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"server: socket\00"
@.str.2 = [13 x i8] c"server: bind\00"
@.str.3 = [15 x i8] c"server: listen\00"
@.str.4 = [15 x i8] c"server: accept\00"
@.str.5 = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i8
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
store i16 1234, i16* %2
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%14 = call i32 @gethostname(i8* %13, i32 64)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%16 = call %struct.hostent* @gethostbyname(i8* %15)
store %struct.hostent* %16, %struct.hostent** %7
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %18, label %23
18: ; preds = %0
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %0
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %11
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i16, i16* %2
%35 = call i32 @htons(i16 zeroext %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %35, i32* %36
%37 = load %struct.hostent*, %struct.hostent** %7
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%41 = load %struct.hostent*, %struct.hostent** %7
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @bcopy(i32 %39, i32* %40, i32 %43)
%45 = load i32, i32* %11
%46 = call i64 @bind(i32 %45, %struct.sockaddr_in* %8, i32 12)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %31
%49 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %31
br label %52
52: ; preds = %51, %85
%53 = load i32, i32* %11
%54 = call i64 @listen(i32 %53, i32 5)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %52
%60 = load i32, i32* %11
%61 = call i32 @accept(i32 %60, %struct.sockaddr_in* %9, i32* %5)
store i32 %61, i32* %12
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %59
%67 = load i32, i32* %12
%68 = call i32* @fdopen(i32 %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %68, i32** %4
br label %69
69: ; preds = %81, %66
%70 = load i32*, i32** %4
%71 = call signext i8 @fgetc(i32* %70)
store i8 %71, i8* %3
%72 = sext i8 %71 to i32
%73 = load i8, i8* @EOF
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %72, %74
br i1 %75, label %76, label %85
76: ; preds = %69
%77 = load i8, i8* %3
%78 = sext i8 %77 to i32
%79 = icmp eq i32 %78, 94
br i1 %79, label %80, label %81
80: ; preds = %76
br label %85
81: ; preds = %76
%82 = load i8, i8* %3
%83 = call i32 @putchar(i8 signext %82)
%84 = call i32 @fflush(i32* null)
br label %69
85: ; preds = %80, %69
br label %52
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
@stderr = global i32 0
@.str = [19 x i8] c"%s: host unknown.\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"server: socket\00"
@.str.2 = [13 x i8] c"server: bind\00"
@.str.3 = [15 x i8] c"server: listen\00"
@.str.4 = [15 x i8] c"server: accept\00"
@.str.5 = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = call i32 @gethostname(i8* %6, i32 64)
%10 = call %struct.hostent* @gethostbyname(i8* %6)
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %6)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i16 zeroext 1234)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 1
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%32 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @bcopy(i32 %30, i32* %31, i32 %33)
%35 = call i64 @bind(i32 %19, %struct.sockaddr_in* %3, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %24
%38 = call i64 @listen(i32 %19, i32 5)
%39 = icmp slt i64 %38, 0
br i1 %39, label %46, label %49
40: ; preds = %24
%41 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %62, %55
%44 = call i64 @listen(i32 %19, i32 5)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43, %37
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %37, %43
%50 = call i32 @accept(i32 %19, %struct.sockaddr_in* %4, i32* %1)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %49
%56 = call i32* @fdopen(i32 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%57 = call signext i8 @fgetc(i32* %56)
%58 = load i8, i8* @EOF
%59 = icmp eq i8 %57, %58
%60 = icmp eq i8 %57, 94
%61 = or i1 %60, %59
br i1 %61, label %43, label %62
62: ; preds = %55, %62
%63 = phi i8 [ %66, %62 ], [ %57, %55 ]
%64 = call i32 @putchar(i8 signext %63)
%65 = call i32 @fflush(i32* null)
%66 = call signext i8 @fgetc(i32* %56)
%67 = load i8, i8* @EOF
%68 = icmp eq i8 %66, %67
%69 = icmp eq i8 %66, 94
%70 = or i1 %69, %68
br i1 %70, label %43, label %62
}