#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_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ PF_LOCAL;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, servlen, n;
  socklen_t clilen;
  struct sockaddr_un cli_addr, serv_addr;
  struct sockaddr *cli_addrPtr;
  struct sockaddr *serv_addrPtr;
  char clientmsg[200];
  int score[7];
  serv_addrPtr = (struct sockaddr *)&serv_addr;
  servlen = sizeof(serv_addr);
  if ((sockfd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0)
    error("creating socket");
  serv_addr.sun_family = PF_LOCAL;
  strcpy(serv_addr.sun_path, "newfile");
  unlink("newfile");
  bind(sockfd, (struct sockaddr *)serv_addrPtr, servlen);
  listen(sockfd, 5);
  while (1) {
    clilen = sizeof(cli_addr);
    newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
    if (newsockfd < 0)
      error("accepting");
    while ((n = read(newsockfd, clientmsg, 200)) > 0) {
      if (clientmsg[0] == 'q') {
        printf("Number of Wins: %d\nNumber of Ties: %d\nNumber of Losses: %d\n",
               atoi(&clientmsg[1]), atoi(&clientmsg[2]), atoi(&clientmsg[4]));
      } else {
        printf("\n%s\n", clientmsg);
      }
    }
  }
  close(newsockfd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x8,-0x1c(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11f9 <main+0x59>
lea    0xe0c(%rip),%rdi
call   1090 <error@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
lea    0xe01(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xdf5(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1080 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
movl   $0x8,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    126c <main+0xcc>
lea    0xdb1(%rip),%rdi
call   1090 <error@plt>
jmp    1271 <main+0xd1>
mov    -0x18(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xc8,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    1318 <main+0x178>
movsbl -0x110(%rbp),%eax
cmp    $0x71,%eax
jne    12fe <main+0x15e>
lea    -0x110(%rbp),%rdi
add    $0x1,%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x138(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x2,%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x134(%rbp)
lea    -0x110(%rbp),%rdi
add    $0x4,%rdi
call   10b0 <atoi@plt>
mov    -0x138(%rbp),%esi
mov    -0x134(%rbp),%edx
mov    %eax,%ecx
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1313 <main+0x173>
lea    -0x110(%rbp),%rsi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1271 <main+0xd1>
jmp    123c <main+0x9c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    0x2e20(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11dc <main+0x3c>
lea    0xe29(%rip),%rdi
call   1090 <error@plt>
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
lea    0xe27(%rip),%rbx
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1080 <bind@plt>
mov    %ebp,0x8(%rsp)
mov    %ebp,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
lea    0x20(%rsp),%r12
lea    0xdfc(%rip),%r13
lea    0xe31(%rip),%r14
nopl   (%rax)
movl   $0x8,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10a0 <accept@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    126d <main+0xcd>
lea    0xdbf(%rip),%rdi
call   1090 <error@plt>
jmp    126d <main+0xcd>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0xc8,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1230 <main+0x90>
cmpb   $0x71,0x20(%rsp)
jne    1260 <main+0xc0>
lea    0x21(%rsp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
lea    0x22(%rsp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
lea    0x24(%rsp),%rdi
call   10b0 <atoi@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    126d <main+0xcd>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"creating socket\00"
@.str.1 = [8 x i8] c"newfile\00"
@.str.2 = [10 x i8] c"accepting\00"
@.str.3 = [60 x i8] c"Number of Wins: %d\0ANumber of Ties: %d\0ANumber of Losses: %d\0A\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
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 %struct.sockaddr_un
%12 = alloca %struct.sockaddr_un
%13 = alloca %struct.sockaddr*
%14 = alloca %struct.sockaddr*
%15 = alloca [200 x i8]
%16 = alloca [7 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast %struct.sockaddr_un* %12 to %struct.sockaddr*
store %struct.sockaddr* %17, %struct.sockaddr** %14
store i32 8, i32* %8
%18 = load i32, i32* @PF_LOCAL
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* @PF_LOCAL
%26 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %12, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @strcpy(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %6
%32 = load %struct.sockaddr*, %struct.sockaddr** %14
%33 = load i32, i32* %8
%34 = call i32 @bind(i32 %31, %struct.sockaddr* %32, i32 %33)
%35 = load i32, i32* %6
%36 = call i32 @listen(i32 %35, i32 5)
br label %37
37: ; preds = %24, %68
store i32 8, i32* %10
%38 = load i32, i32* %6
%39 = bitcast %struct.sockaddr_un* %11 to %struct.sockaddr*
%40 = call i32 @accept(i32 %38, %struct.sockaddr* %39, i32* %10)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
br label %46
46: ; preds = %67, %45
%47 = load i32, i32* %7
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%49 = call i32 @read(i32 %47, i8* %48, i32 200)
store i32 %49, i32* %9
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %68
51: ; preds = %46
%52 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 113
br i1 %55, label %56, label %64
56: ; preds = %51
%57 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 1
%58 = call i32 @atoi(i8* %57)
%59 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 2
%60 = call i32 @atoi(i8* %59)
%61 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 4
%62 = call i32 @atoi(i8* %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %58, i32 %60, i32 %62)
br label %67
64: ; preds = %51
%65 = getelementptr inbounds [200 x i8], [200 x i8]* %15, i64 0, i64 0
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %64, %56
br label %46
68: ; preds = %46
br label %37
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"creating socket\00"
@.str.1 = [8 x i8] c"newfile\00"
@.str.2 = [10 x i8] c"accepting\00"
@.str.3 = [60 x i8] c"Number of Wins: %d\0ANumber of Ties: %d\0ANumber of Losses: %d\0A\00"
@.str.4 = [5 x i8] c"\0A%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_un
%5 = alloca %struct.sockaddr_un
%6 = alloca [200 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_un* %4 to i8*
%9 = bitcast %struct.sockaddr_un* %5 to i8*
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%11 = bitcast %struct.sockaddr_un* %5 to %struct.sockaddr*
%12 = load i32, i32* @PF_LOCAL
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i32, i32* @PF_LOCAL
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %5, i64 0, i32 1
store i32 %19, i32* %20
%21 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @unlink(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @bind(i32 %14, %struct.sockaddr* %11, i32 8)
%24 = call i32 @listen(i32 %14, i32 5)
%25 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 1
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 2
%28 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 4
br label %29
29: ; preds = %37, %18
store i32 8, i32* %3
%30 = call i32 @accept(i32 %14, %struct.sockaddr* %25, i32* %3)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @error(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = call i32 @read(i32 %30, i8* %10, i32 200)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %48, %34
br label %29
38: ; preds = %34, %48
%39 = load i8, i8* %10
%40 = icmp eq i8 %39, 113
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = call i32 @atoi(i8* %26)
%43 = call i32 @atoi(i8* %27)
%44 = call i32 @atoi(i8* %28)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %43, i32 %44)
br label %48
46: ; preds = %38
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %48
48: ; preds = %46, %41
%49 = call i32 @read(i32 %30, i8* %10, i32 200)
%50 = icmp sgt i32 %49, 0
br i1 %50, label %38, label %37
}