#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ AcceptSock(int *, int);
scalar_t__ CreateSock(int *, int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main() {
  int nSock, nSock1;
  char buf[2048];
  if (CreateSock(&nSock, 9001, 9) != 0) {
    fprintf(stderr, "%s failed.\n", "Create Listen SOCKET");
    return 0;
  } else
    fprintf(stderr, "%s success.\n", "Create Listen SOCKET");
  ;
  if (AcceptSock(&nSock1, nSock) != 0) {
    fprintf(stderr, "%s failed.\n", "Link");
    return 0;
  } else
    fprintf(stderr, "%s success.\n", "Link");
  ;
  memset(buf, 0, sizeof(buf));
  recv(nSock1, buf, sizeof(buf), 0);
  fprintf(stderr, buf);
  close(nSock);
  close(nSock1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
mov    $0x2329,%esi
mov    $0x9,%edx
call   1080 <CreateSock@plt>
cmp    $0x0,%rax
je     11b9 <main+0x59>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
lea    0xe66(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128c <main+0x12c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
lea    0xe3c(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%esi
lea    -0xc(%rbp),%rdi
call   1070 <AcceptSock@plt>
cmp    $0x0,%rax
je     1217 <main+0xb7>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
lea    0xe2a(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    128c <main+0x12c>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
lea    0xe00(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x818,%rsp
lea    0xc(%rsp),%rdi
mov    $0x2329,%esi
mov    $0x9,%edx
call   1080 <CreateSock@plt>
mov    0x2e5b(%rip),%rbx
mov    (%rbx),%edi
test   %rax,%rax
je     119c <main+0x3c>
lea    0xe6d(%rip),%rsi
lea    0xe72(%rip),%rdx
jmp    11d4 <main+0x74>
lea    0xe7e(%rip),%rsi
lea    0xe62(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0xc(%rsp),%esi
lea    0x8(%rsp),%rdi
call   1070 <AcceptSock@plt>
mov    (%rbx),%edi
test   %rax,%rax
je     11e8 <main+0x88>
lea    0xe33(%rip),%rsi
lea    0xe5a(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe32(%rip),%rsi
lea    0xe38(%rip),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0x800,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    (%rbx),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
jmp    11db <main+0x7b>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"%s failed.\0A\00"
@.str.1 = [21 x i8] c"Create Listen SOCKET\00"
@.str.2 = [13 x i8] c"%s success.\0A\00"
@.str.3 = [5 x i8] c"Link\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2048 x i8]
store i32 0, i32* %1
%5 = call i64 @CreateSock(i32* %2, i32 9001, i32 9)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %36
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10
%14 = load i32, i32* %2
%15 = call i64 @AcceptSock(i32* %3, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %36
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %20
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 2048)
%26 = load i32, i32* %3
%27 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%28 = call i32 @recv(i32 %26, i8* %27, i32 2048, i32 0)
%29 = load i32, i32* @stderr
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* %30)
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
store i32 0, i32* %1
br label %36
36: ; preds = %23, %17, %7
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"%s failed.\0A\00"
@.str.1 = [21 x i8] c"Create Listen SOCKET\00"
@.str.2 = [13 x i8] c"%s success.\0A\00"
@.str.3 = [5 x i8] c"Link\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2048 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = call i64 @CreateSock(i32* %1, i32 9001, i32 9)
%8 = icmp eq i64 %7, 0
%9 = load i32, i32* @stderr
br i1 %8, label %12, label %10
10: ; preds = %0
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %31
12: ; preds = %0
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %1
%15 = call i64 @AcceptSock(i32* %2, i32 %14)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* @stderr
br i1 %16, label %20, label %18
18: ; preds = %12
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %31
20: ; preds = %12
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @memset(i8* %6, i32 0, i32 2048)
%23 = load i32, i32* %2
%24 = call i32 @recv(i32 %23, i8* %6, i32 2048, i32 0)
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* %6)
%27 = load i32, i32* %1
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %2
%30 = call i32 @close(i32 %29)
br label %31
31: ; preds = %20, %18, %10
ret i32 0
}