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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ isalpha(char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, int);
int recv(int, char *, int);
int strlen(char *);
int getData(int sockfd, char *data) {
  char buffer[32];
  int n;
  int i = 0;
  int j = 0;
  bzero(data, sizeof(data));
  if ((n = recv(sockfd, buffer, 31)) < 0) {
    perror("ERROR reading from socket");
  }
  for (i = 0; i < strlen(buffer); i++) {
    if (isalpha(buffer[i])) {
      data[j] = buffer[i];
      j++;
    }
  }
  buffer[n] = '\0';
  printf("buffer is %s lenght of bufer is %d data readin is %d\n", data,
         strlen(data), n);
  return atoi(buffer);
}


x86 assembly (clang, -O0):
<getData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1080 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1f,%edx
call   1030 <recv@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11c4 <getData+0x54>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jge    122e <getData+0xbe>
movslq -0x38(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
je     121b <getData+0xab>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1220 <getData+0xb0>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11cb <getData+0x5b>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
mov    -0x34(%rbp),%ecx
lea    0xdc2(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1090 <atoi@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getData>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rsi,%rdi
mov    $0x8,%esi
call   1080 <bzero@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1f,%edx
call   1030 <recv@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1229 <getData+0xb9>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11f1 <getData+0x81>
xor    %ebx,%ebx
mov    %rsp,%r12
xor    %ebp,%ebp
jmp    11d3 <getData+0x63>
nopl   (%rax)
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11f1 <getData+0x81>
movsbl (%rsp,%rbx,1),%edi
call   1060 <isalpha@plt>
test   %rax,%rax
je     11c0 <getData+0x50>
movzbl (%rsp,%rbx,1),%eax
movslq %ebp,%rbp
mov    %al,(%r15,%rbp,1)
add    $0x1,%ebp
jmp    11c0 <getData+0x50>
movslq %r14d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0xe13(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r14d,%ecx
call   1050 <printf@plt>
mov    %rsp,%rdi
call   1090 <atoi@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
jmp    11a8 <getData+0x38>

LLVM IR (-O0):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [54 x i8] c"buffer is %s lenght of bufer is %d data readin is %d\0A\00"
define i32 @getData(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = call i32 @bzero(i8* %9, i32 8)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%13 = call i32 @recv(i32 %11, i8* %12, i32 31)
store i32 %13, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
store i32 0, i32* %7
br label %18
18: ; preds = %42, %17
%19 = load i32, i32* %7
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %45
23: ; preds = %18
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @isalpha(i8 signext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %23
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = load i8*, i8** %4
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %41
41: ; preds = %30, %23
br label %42
42: ; preds = %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %18
45: ; preds = %18
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %4
%50 = load i8*, i8** %4
%51 = call i32 @strlen(i8* %50)
%52 = load i32, i32* %6
%53 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %49, i32 %51, i32 %52)
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%55 = call i32 @atoi(i8* %54)
ret i32 %55
}

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [54 x i8] c"buffer is %s lenght of bufer is %d data readin is %d\0A\00"
define i32 @getData(i32 %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @bzero(i8* %1, i32 8)
%6 = call i32 @recv(i32 %0, i8* %4, i32 31)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = call i32 @strlen(i8* %4)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %10, %25
%14 = phi i64 [ %27, %25 ], [ 0, %10 ]
%15 = phi i32 [ %26, %25 ], [ 0, %10 ]
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %14
%17 = load i8, i8* %16
%18 = call i64 @isalpha(i8 signext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %13
%21 = load i8, i8* %16
%22 = sext i32 %15 to i64
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 %21, i8* %23
%24 = add nsw i32 %15, 1
br label %25
25: ; preds = %13, %20
%26 = phi i32 [ %24, %20 ], [ %15, %13 ]
%27 = add nuw nsw i64 %14, 1
%28 = call i32 @strlen(i8* %4)
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %13, label %31
31: ; preds = %25, %10
%32 = sext i32 %6 to i64
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 @strlen(i8* %1)
%35 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %34, i32 %6)
%36 = call i32 @atoi(i8* %4)
ret i32 %36
}