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

/* Variables and functions */
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int tcp_serv_init(int);
int main() {
  int servfd = tcp_serv_init(4567);
  int newfd;
  printf("waiting for client......\n");
  newfd = accept(servfd, NULL, NULL);
  printf("sucess to connect\n");
  char str[1024];
  while (1) {
    read(newfd, str, 1024);
    printf("%s\n", str);
  }
  close(newfd);
  close(servfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x11d7,%edi
call   1060 <tcp_serv_init@plt>
mov    %eax,-0x8(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <accept@plt>
mov    %eax,-0xc(%rbp)
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
lea    -0x410(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118d <main+0x4d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    $0x11d7,%edi
call   1060 <tcp_serv_init@plt>
mov    %eax,%ebx
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <accept@plt>
mov    %eax,%ebp
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@.str = [26 x i8] c"waiting for client......\0A\00"
@.str.1 = [19 x i8] c"sucess to connect\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = call i32 @tcp_serv_init(i32 4567)
store i32 %5, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = call i32 @accept(i32 %7, i32* null, i32* null)
store i32 %8, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %0, %10
%11 = load i32, i32* %3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 1024)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %10
}

LLVM IR (-O2):
@str = [25 x i8] c"waiting for client......\00"
@str.3 = [18 x i8] c"sucess to connect\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @tcp_serv_init(i32 4567)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @accept(i32 %2, i32* null, i32* null)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
br label %7
7: ; preds = %7, %0
%8 = call i32 @read(i32 %4, i8* %6, i32 1024)
%9 = call i32 @puts(i8* %6)
br label %7
}