#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bind(int (*)(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/),
                        struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int (*)(int /*<<< orphan*/, int /*<<< orphan*/,
                                 int /*<<< orphan*/));
char getCardSymbol(unsigned char);
unsigned char getCardValue(char);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int rand();
int /*<<< orphan*/
recvfrom(int (*)(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/),
         char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/
sendto(int (*)(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/),
       char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int _socket, n, port;
  struct sockaddr_in server, client;
  char buffer[1];
  port = atoi(argv[1]);
  if (port == 0) {
    printf("\"%s\" should be a port number!\n", argv[1]);
    return 1;
  }
  _socket = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&server, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = htonl(INADDR_ANY);
  server.sin_port = htons(port);
  bind(socket, (struct sockaddr *)&server, sizeof(server));
  srand(time(NULL));
  int server_sum = 0, client_sum = 0;
  unsigned short cards_used = 0;
  while (client_sum <= 21 && server_sum <= 21) {
    int length = sizeof(client);
    recvfrom(socket, buffer, 1, 0, (struct sockaddr *)&client, &length);
    unsigned char card;
    client_sum += card = getCardValue(buffer[0]);
    if (client_sum > 21)
      break;
    cards_used |= 1 << (16 - card);
    do
      card = (unsigned char)(rand() % 13 + 1);
    while ((cards_used >> card) & 1 == 1);
    cards_used |= 1 << (16 - card);
    server_sum += card;
    buffer[0] = getCardSymbol(card);
    sendto(socket, buffer, 1, 0, (struct sockaddr *)&server, sizeof(server));
  }
  close(socket);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1230 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13df <main+0x1ff>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1118 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rsi
mov    0x2d6b(%rip),%rdi
mov    $0xc,%edx
call   10d0 <bind@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movw   $0x0,-0x46(%rbp)
xor    %eax,%eax
cmpl   $0x15,-0x44(%rbp)
mov    %al,-0x4e(%rbp)
jg     12d4 <main+0xf4>
cmpl   $0x15,-0x40(%rbp)
setle  %al
mov    %al,-0x4e(%rbp)
mov    -0x4e(%rbp),%al
test   $0x1,%al
jne    12e4 <main+0x104>
jmp    13d3 <main+0x1f3>
movl   $0xc,-0x4c(%rbp)
lea    -0x39(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    0x2cfe(%rip),%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    -0x4c(%rbp),%r9
call   10c0 <recvfrom@plt>
movsbl -0x39(%rbp),%edi
call   10a0 <getCardValue@plt>
mov    %al,-0x4d(%rbp)
movzbl %al,%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x15,-0x44(%rbp)
jle    132e <main+0x14e>
jmp    13d3 <main+0x1f3>
movzbl -0x4d(%rbp),%eax
mov    $0x10,%ecx
sub    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzwl -0x46(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x46(%rbp)
mov    $0x0,%al
call   1100 <rand@plt>
mov    $0xd,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %dl,%al
mov    %al,-0x4d(%rbp)
movzwl -0x46(%rbp),%eax
movzbl -0x4d(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    134c <main+0x16c>
movzbl -0x4d(%rbp),%eax
mov    $0x10,%ecx
sub    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzwl -0x46(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x46(%rbp)
movzbl -0x4d(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
movzbl -0x4d(%rbp),%edi
call   1030 <getCardSymbol@plt>
mov    %al,-0x39(%rbp)
lea    -0x39(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    0x2c3c(%rip),%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
jmp    12bb <main+0xdb>
mov    0x2c1e(%rip),%rdi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x8(%rsi),%rbp
mov    %rbp,%rdi
call   10f0 <atoi@plt>
test   %eax,%eax
je     1364 <main+0x184>
mov    %eax,%ebx
mov    0x2dd5(%rip),%r14
mov    (%r14),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1118 <socket@plt>
mov    0x2dd3(%rip),%r15
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
lea    0x3(%rsp),%rbx
xor    %r14d,%r14d
xor    %r13d,%r13d
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r13d,%ebp
movl   $0xc,0x4(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    0x18(%rsp),%r8
lea    0x4(%rsp),%r9
call   10c0 <recvfrom@plt>
movsbl 0x3(%rsp),%edi
call   10a0 <getCardValue@plt>
movzbl %al,%r13d
add    %ebp,%r13d
cmp    $0x16,%r13d
jae    1354 <main+0x174>
mov    $0x10,%cl
sub    %al,%cl
bts    %ecx,%r14d
movzwl %r14w,%r14d
xchg   %ax,%ax
xor    %eax,%eax
call   1100 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%edx
lea    (%rcx,%rdx,4),%ecx
sub    %ecx,%eax
add    $0x1,%al
movzbl %al,%ebp
bt     %ebp,%r14d
jb     12e0 <main+0x100>
mov    %ebp,%edi
call   1030 <getCardSymbol@plt>
mov    %al,0x3(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
lea    0x8(%rsp),%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0x15,%r13d
ja     1354 <main+0x174>
mov    $0x10,%al
sub    %bpl,%al
bts    %eax,%r14d
add    %ebp,%r12d
cmp    $0x16,%r12d
jb     1290 <main+0xb0>
mov    0x2c9d(%rip),%rdi
call   1080 <close@plt>
xor    %eax,%eax
jmp    1378 <main+0x198>
lea    0xc95(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [31 x i8] c"\22%s\22 should be a port number!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = 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 %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca [1 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i16
%15 = alloca i32
%16 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %26)
store i32 1, i32* %3
br label %110
28: ; preds = %2
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %6
%32 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %36, i32* %38
%39 = load i32, i32* %8
%40 = call i32 @htons(i32 %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %40, i32* %41
%42 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%43 = call i32 @bind(i32 (i32, i32, i32)* @socket, %struct.sockaddr* %42, i32 12)
%44 = call i32 @time(i32* null)
%45 = call i32 @srand(i32 %44)
store i32 0, i32* %12
store i32 0, i32* %13
store i16 0, i16* %14
br label %46
46: ; preds = %89, %28
%47 = load i32, i32* %13
%48 = icmp sle i32 %47, 21
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32, i32* %12
%51 = icmp sle i32 %50, 21
br label %52
52: ; preds = %49, %46
%53 = phi i1 [ false, %46 ], [ %51, %49 ]
br i1 %53, label %54, label %108
54: ; preds = %52
store i32 12, i32* %15
%55 = getelementptr inbounds [1 x i8], [1 x i8]* %11, i64 0, i64 0
%56 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%57 = call i32 @recvfrom(i32 (i32, i32, i32)* @socket, i8* %55, i32 1, i32 0, %struct.sockaddr* %56, i32* %15)
%58 = getelementptr inbounds [1 x i8], [1 x i8]* %11, i64 0, i64 0
%59 = load i8, i8* %58
%60 = call zeroext i8 @getCardValue(i8 signext %59)
store i8 %60, i8* %16
%61 = zext i8 %60 to i32
%62 = load i32, i32* %13
%63 = add nsw i32 %62, %61
store i32 %63, i32* %13
%64 = load i32, i32* %13
%65 = icmp sgt i32 %64, 21
br i1 %65, label %66, label %67
66: ; preds = %54
br label %108
67: ; preds = %54
%68 = load i8, i8* %16
%69 = zext i8 %68 to i32
%70 = sub nsw i32 16, %69
%71 = shl i32 1, %70
%72 = load i16, i16* %14
%73 = zext i16 %72 to i32
%74 = or i32 %73, %71
%75 = trunc i32 %74 to i16
store i16 %75, i16* %14
br label %76
76: ; preds = %81, %67
%77 = call i32 (...) @rand()
%78 = srem i32 %77, 13
%79 = add nsw i32 %78, 1
%80 = trunc i32 %79 to i8
store i8 %80, i8* %16
br label %81
81: ; preds = %76
%82 = load i16, i16* %14
%83 = zext i16 %82 to i32
%84 = load i8, i8* %16
%85 = zext i8 %84 to i32
%86 = ashr i32 %83, %85
%87 = and i32 %86, 1
%88 = icmp ne i32 %87, 0
br i1 %88, label %76, label %89
89: ; preds = %81
%90 = load i8, i8* %16
%91 = zext i8 %90 to i32
%92 = sub nsw i32 16, %91
%93 = shl i32 1, %92
%94 = load i16, i16* %14
%95 = zext i16 %94 to i32
%96 = or i32 %95, %93
%97 = trunc i32 %96 to i16
store i16 %97, i16* %14
%98 = load i8, i8* %16
%99 = zext i8 %98 to i32
%100 = load i32, i32* %12
%101 = add nsw i32 %100, %99
store i32 %101, i32* %12
%102 = load i8, i8* %16
%103 = call signext i8 @getCardSymbol(i8 zeroext %102)
%104 = getelementptr inbounds [1 x i8], [1 x i8]* %11, i64 0, i64 0
store i8 %103, i8* %104
%105 = getelementptr inbounds [1 x i8], [1 x i8]* %11, i64 0, i64 0
%106 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%107 = call i32 @sendto(i32 (i32, i32, i32)* @socket, i8* %105, i32 1, i32 0, %struct.sockaddr* %106, i32 12)
br label %46
108: ; preds = %66, %52
%109 = call i32 @close(i32 (i32, i32, i32)* @socket)
br label %110
110: ; preds = %108, %23
%111 = load i32, i32* %3
ret i32 %111
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [31 x i8] c"\22%s\22 should be a port number!\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [1 x i8]
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %73
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(%struct.sockaddr_in* %3, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = tail call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = tail call i32 @htons(i32 %12)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i32 @bind(i32 (i32, i32, i32)* @socket, %struct.sockaddr* %28, i32 12)
%30 = call i32 @time(i32* null)
%31 = call i32 @srand(i32 %30)
%32 = bitcast i32* %6 to i8*
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %34
34: ; preds = %16, %60
%35 = phi i16 [ 0, %16 ], [ %64, %60 ]
%36 = phi i32 [ 0, %16 ], [ %42, %60 ]
%37 = phi i32 [ 0, %16 ], [ %65, %60 ]
store i32 12, i32* %6
%38 = call i32 @recvfrom(i32 (i32, i32, i32)* @socket, i8* %9, i32 1, i32 0, %struct.sockaddr* %33, i32* %6)
%39 = load i8, i8* %9
%40 = call zeroext i8 @getCardValue(i8 signext %39)
%41 = zext i8 %40 to i32
%42 = add nuw nsw i32 %36, %41
%43 = icmp ugt i32 %42, 21
br i1 %43, label %44, label %45
44: ; preds = %34
br label %71
45: ; preds = %34
%46 = sub nsw i32 16, %41
%47 = shl nuw nsw i32 1, %46
%48 = trunc i32 %47 to i16
%49 = or i16 %35, %48
%50 = zext i16 %49 to i32
br label %51
51: ; preds = %51, %45
%52 = call i32 (...) @rand()
%53 = srem i32 %52, 13
%54 = trunc i32 %53 to i8
%55 = add nsw i8 %54, 1
%56 = zext i8 %55 to i32
%57 = shl nuw i32 1, %56
%58 = and i32 %57, %50
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %51
60: ; preds = %51
%61 = sub nsw i32 16, %56
%62 = shl nuw nsw i32 1, %61
%63 = trunc i32 %62 to i16
%64 = or i16 %49, %63
%65 = add nuw nsw i32 %37, %56
%66 = call signext i8 @getCardSymbol(i8 zeroext %55)
store i8 %66, i8* %9
%67 = call i32 @sendto(i32 (i32, i32, i32)* @socket, i8* %9, i32 1, i32 0, %struct.sockaddr* %28, i32 12)
%68 = icmp ult i32 %42, 22
%69 = icmp ult i32 %65, 22
%70 = select i1 %68, i1 %69, i1 false
br i1 %70, label %34, label %71
71: ; preds = %60, %44
%72 = call i32 @close(i32 (i32, i32, i32)* @socket)
br label %73
73: ; preds = %71, %14
%74 = phi i32 [ 1, %14 ], [ 0, %71 ]
ret i32 %74
}