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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int fork();
int getpid();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ wait(int *);
int main() {
  int fd = socket(PF_INET, SOCK_STREAM, 0);
  int connfd;
  int pid;
  char sendbuff[1024];
  struct sockaddr_in serveraddr;
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serveraddr.sin_port = htons(1234);
  bind(fd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
  listen(fd, 1024);
  int i;
  for (i = 0; i < 10; i++) {
    int pid = fork();
    if (pid == 0) {
      while (1) {
        connfd = accept(fd, (struct sockaddr *)NULL, NULL);
        snprintf(sendbuff, sizeof(sendbuff), "accept PID is %d\n", getpid());
        send(connfd, sendbuff, strlen(sendbuff) + 1, 0);
        printf("process %d accept success!\n", getpid());
        close(connfd);
      }
    }
  }
  int status;
  wait(&status);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x41c(%rbp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,-0x420(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x400,%esi
call   10b0 <listen@plt>
movl   $0x0,-0x424(%rbp)
cmpl   $0xa,-0x424(%rbp)
jge    1359 <main+0x179>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jne    1340 <main+0x160>
jmp    1298 <main+0xb8>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10d0 <accept@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x450(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x450(%rbp),%rdi
mov    %eax,%ecx
mov    $0x400,%esi
lea    0xd2c(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x438(%rbp)
xor    %ecx,%ecx
call   1060 <send@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xce4(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%edi
call   10a0 <close@plt>
jmp    1298 <main+0xb8>
jmp    1345 <main+0x165>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    126c <main+0x8c>
lea    -0x42c(%rbp),%rdi
call   10e0 <wait@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r14d
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    %r14d,%edi
mov    $0x400,%esi
call   10b0 <listen@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12e0 <main+0x100>
lea    0x10(%rsp),%rdi
call   10e0 <wait@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <accept@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd04(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xcdc(%rip),%rdi
mov    %eax,%esi
call   1070 <printf@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
jmp    12e0 <main+0x100>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [18 x i8] c"accept PID is %d\0A\00"
@.str.1 = [28 x i8] c"process %d accept success!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 1234)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = load i32, i32* %2
%25 = call i32 @listen(i32 %24, i32 1024)
store i32 0, i32* %7
br label %26
26: ; preds = %51, %0
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 10
br i1 %28, label %29, label %54
29: ; preds = %26
%30 = call i32 (...) @fork()
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %29
br label %34
34: ; preds = %33, %34
%35 = load i32, i32* %2
%36 = call i32 @accept(i32 %35, %struct.sockaddr* null, i32* null)
store i32 %36, i32* %3
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%38 = call i32 (...) @getpid()
%39 = call i32 @snprintf(i8* %37, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %3
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%43 = call i64 @strlen(i8* %42)
%44 = add nsw i64 %43, 1
%45 = call i32 @send(i32 %40, i8* %41, i64 %44, i32 0)
%46 = call i32 (...) @getpid()
%47 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
%49 = call i32 @close(i32 %48)
br label %34
50: ; preds = %29
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %26
54: ; preds = %26
%55 = call i32 @wait(i32* %9)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [18 x i8] c"accept PID is %d\0A\00"
@.str.1 = [28 x i8] c"process %d accept success!\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @INADDR_ANY
%12 = tail call i32 @htonl(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 1234)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%17 = call i32 @bind(i32 %6, %struct.sockaddr* %16, i32 12)
%18 = call i32 @listen(i32 %6, i32 1024)
%19 = call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %46, %43, %40, %37, %34, %31, %28, %25, %22, %0
br label %52
22: ; preds = %0
%23 = call i32 (...) @fork()
%24 = icmp eq i32 %23, 0
br i1 %24, label %21, label %25
25: ; preds = %22
%26 = call i32 (...) @fork()
%27 = icmp eq i32 %26, 0
br i1 %27, label %21, label %28
28: ; preds = %25
%29 = call i32 (...) @fork()
%30 = icmp eq i32 %29, 0
br i1 %30, label %21, label %31
31: ; preds = %28
%32 = call i32 (...) @fork()
%33 = icmp eq i32 %32, 0
br i1 %33, label %21, label %34
34: ; preds = %31
%35 = call i32 (...) @fork()
%36 = icmp eq i32 %35, 0
br i1 %36, label %21, label %37
37: ; preds = %34
%38 = call i32 (...) @fork()
%39 = icmp eq i32 %38, 0
br i1 %39, label %21, label %40
40: ; preds = %37
%41 = call i32 (...) @fork()
%42 = icmp eq i32 %41, 0
br i1 %42, label %21, label %43
43: ; preds = %40
%44 = call i32 (...) @fork()
%45 = icmp eq i32 %44, 0
br i1 %45, label %21, label %46
46: ; preds = %43
%47 = call i32 (...) @fork()
%48 = icmp eq i32 %47, 0
br i1 %48, label %21, label %49
49: ; preds = %46
%50 = bitcast i32* %3 to i8*
%51 = call i32 @wait(i32* %3)
ret i32 0
52: ; preds = %21, %52
%53 = call i32 @accept(i32 %6, %struct.sockaddr* null, i32* null)
%54 = call i32 (...) @getpid()
%55 = call i32 @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %54)
%56 = call i64 @strlen(i8* %7)
%57 = add nsw i64 %56, 1
%58 = call i32 @send(i32 %53, i8* %7, i64 %57, i32 0)
%59 = call i32 (...) @getpid()
%60 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = call i32 @close(i32 %53)
br label %52
}