#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*/ client_addr;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char **, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sscanf(char *, char *, int *, char *, int *);
int main(int Count, char *Strings[]) {
  int sockfd;
  struct sockaddr_in addr;
  char buffer[1024];
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Socket creation failed");
    exit(errno);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(9999);
  addr.sin_addr.s_addr = INADDR_ANY;
  if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != 0) {
    perror("socket-bind");
    exit(errno);
  }
  if (listen(sockfd, 20) != 0) {
    perror("error listening");
    exit(errno);
  } else {
    printf("Listening\n");
  }
  int clientfd;
  struct sockaddr_in client_addr;
  int addrlen = sizeof(client_addr);
  clientfd = accept(sockfd, (struct sockaddr *)&client_addr, &addrlen);
  printf("%s:%d", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
  bzero(&buffer, sizeof(buffer));
  recv(clientfd, buffer, sizeof(buffer), 0);
  int num1, num2;
  char c;
  sscanf(buffer, "%d%c%d", &num1, &c, &num2);
  printf("\ndata is %d--%c--%d", num1, c, num2);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1238 <main+0x58>
lea    0xddb(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
je     1292 <main+0xb2>
lea    0xd98(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x14,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
je     12c3 <main+0xe3>
lea    0xd73(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xc,-0x434(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x434(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x424(%rbp)
mov    -0x42c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x448(%rbp)
mov    -0x430(%rbp),%edi
call   10a0 <ntohs@plt>
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
mov    -0x424(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x420(%rbp),%rdi
lea    0xce1(%rip),%rsi
lea    -0x438(%rbp),%rdx
lea    -0x43d(%rbp),%rcx
lea    -0x43c(%rbp),%r8
call   1090 <sscanf@plt>
mov    -0x438(%rbp),%esi
movsbl -0x43d(%rbp),%edx
mov    -0x43c(%rbp),%ecx
lea    0xcb4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x430,%rsp
mov    0x2de6(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     1332 <main+0x142>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2da5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    133b <main+0x14b>
mov    %ebx,%edi
mov    $0x14,%esi
call   1090 <listen@plt>
test   %rax,%rax
jne    1344 <main+0x154>
lea    0xddd(%rip),%rdi
call   1040 <puts@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10f0 <accept@plt>
mov    %eax,%r14d
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x20(%rsp),%edi
call   10b0 <ntohs@plt>
lea    0xd7f(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
call   10e0 <bzero@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd4e(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x3(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rbp,%rdi
call   10a0 <sscanf@plt>
mov    0x8(%rsp),%esi
movsbl 0x3(%rsp),%edx
mov    0x4(%rsp),%ecx
lea    0xd2a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xcc7(%rip),%rdi
jmp    134b <main+0x15b>
lea    0xcd5(%rip),%rdi
jmp    134b <main+0x15b>
lea    0xcd8(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"Socket creation failed\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [12 x i8] c"socket-bind\00"
@.str.2 = [16 x i8] c"error listening\00"
@.str.3 = [11 x i8] c"Listening\0A\00"
@.str.4 = [6 x i8] c"%s:%d\00"
@.str.5 = [7 x i8] c"%d%c%d\00"
@.str.6 = [20 x i8] c"\0Adata is %d--%c--%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @errno
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 9999)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%33 = call i64 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %23
%36 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @errno
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %23
%40 = load i32, i32* %6
%41 = call i64 @listen(i32 %40, i32 20)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @errno
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47
store i32 12, i32* %11
%50 = load i32, i32* %6
%51 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%52 = call i32 @accept(i32 %50, %struct.sockaddr* %51, i32* %11)
store i32 %52, i32* %9
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i8* @inet_ntoa(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%58 = load i32, i32* %57
%59 = call i32 @ntohs(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %56, i32 %59)
%61 = bitcast [1024 x i8]* %8 to i8**
%62 = call i32 @bzero(i8** %61, i32 1024)
%63 = load i32, i32* %9
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = call i32 @recv(i32 %63, i8* %64, i32 1024, i32 0)
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = call i32 @sscanf(i8* %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %12, i8* %14, i32* %13)
%68 = load i32, i32* %12
%69 = load i8, i8* %14
%70 = sext i8 %69 to i32
%71 = load i32, i32* %13
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %68, i32 %70, i32 %71)
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"Socket creation failed\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [12 x i8] c"socket-bind\00"
@.str.2 = [16 x i8] c"error listening\00"
@.str.4 = [6 x i8] c"%s:%d\00"
@.str.5 = [7 x i8] c"%d%c%d\00"
@.str.6 = [20 x i8] c"\0Adata is %d--%c--%d\00"
@str = [10 x i8] c"Listening\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* @AF_INET
%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 %20
16: ; preds = %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%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 = tail call i32 @htons(i32 9999)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i64 @bind(i32 %14, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %20
%31 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @errno
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %20
%35 = call i64 @listen(i32 %14, i32 20)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @errno
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %34
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%43 = bitcast %struct.sockaddr_in* %5 to i8*
%44 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%45 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%46 = call i32 @accept(i32 %14, %struct.sockaddr* %45, i32* %6)
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%48 = load i32, i32* %47
%49 = call i8* @inet_ntoa(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @ntohs(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %49, i32 %52)
%54 = bitcast [1024 x i8]* %4 to i8**
%55 = call i32 @bzero(i8** %54, i32 1024)
%56 = call i32 @recv(i32 %46, i8* %11, i32 1024, i32 0)
%57 = bitcast i32* %7 to i8*
%58 = bitcast i32* %8 to i8*
%59 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %7, i8* %9, i32* %8)
%60 = load i32, i32* %7
%61 = load i8, i8* %9
%62 = sext i8 %61 to i32
%63 = load i32, i32* %8
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %60, i32 %62, i32 %63)
%65 = call i32 @close(i32 %14)
ret i32 0
}