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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process_client_message(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
void process_client_connection(void) {
  FILE *fd;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  int count_lines, count_lines_ok;
  count_lines = count_lines_ok = 0;
  char config_file[] = "parseMsg_client_training.txt";
  if ((fd = fopen(config_file, "r")) == NULL) {
    printf("Unable to load config file named %s", config_file);
    exit(1);
  }
  while ((read = getline(&line, &len, fd)) != -1) {
    fflush(stdout);
    count_lines++;
    if ((strncmp(line, "END", strlen("END")))) {
      process_client_message(line);
      count_lines_ok++;
    }
  }
  printf("\n#> Number of msgs  processed from client: %d", count_lines);
  printf("\n#> Number of valid msgs  processed from client: %d \n",
         count_lines_ok);
  if (fd)
    fclose(fd);
  if (line)
    free(line);
}


x86 assembly (clang, -O0):
<process_client_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0xe33(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe30(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe2d(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe2b(%rip),%eax
mov    %eax,-0x38(%rbp)
mov    0xe26(%rip),%al
mov    %al,-0x34(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1233 <process_client_connection+0x93>
lea    -0x50(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    1238 <process_client_connection+0x98>
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     12b3 <process_client_connection+0x113>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xdc8(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xdb6(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     12ae <process_client_connection+0x10e>
mov    -0x10(%rbp),%rdi
call   1080 <process_client_message@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1238 <process_client_connection+0x98>
mov    -0x20(%rbp),%esi
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     12e9 <process_client_connection+0x149>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x10(%rbp)
je     12fd <process_client_connection+0x15d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_client_connection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movups 0xe47(%rip),%xmm0
movups %xmm0,0x1d(%rsp)
movaps 0xe2e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe3f(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12b9 <process_client_connection+0x119>
mov    %rax,%r14
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     1270 <process_client_connection+0xd0>
xor    %ebp,%ebp
lea    0xe31(%rip),%r15
lea    0x8(%rsp),%r13
xor    %ebx,%ebx
jmp    1236 <process_client_connection+0x96>
nopl   0x0(%rax,%rax,1)
mov    %rsp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   10b0 <getline@plt>
add    $0x1,%ebx
cmp    $0xffffffff,%eax
je     1274 <process_client_connection+0xd4>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    (%rsp),%r12
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1220 <process_client_connection+0x80>
mov    (%rsp),%rdi
call   1080 <process_client_message@plt>
add    $0x1,%ebp
jmp    1220 <process_client_connection+0x80>
xor    %ebx,%ebx
xor    %ebp,%ebp
lea    0xdcc(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdea(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     12aa <process_client_connection+0x10a>
call   1030 <free@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5f(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@__const.process_client_connection.config_file = [29 x i8] c"parseMsg_client_training.txt\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"Unable to load config file named %s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"END\00"
@.str.3 = [46 x i8] c"\0A#> Number of msgs processed from client: %d\00"
@.str.4 = [54 x i8] c"\0A#> Number of valid msgs processed from client: %d \0A\00"
define void @process_client_connection() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [29 x i8]
store i8* null, i8** %2
store i64 0, i64* %3
store i32 0, i32* %6
store i32 0, i32* %5
%8 = bitcast [29 x i8]* %7 to i8*
%9 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %1
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = getelementptr inbounds [29 x i8], [29 x i8]* %7, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
br label %17
17: ; preds = %35, %16
%18 = load i32*, i32** %1
%19 = call i32 @getline(i8** %2, i64* %3, i32* %18)
store i32 %19, i32* %4
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load i32, i32* @stdout
%23 = call i32 @fflush(i32 %22)
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = load i8*, i8** %2
%27 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%28 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %21
%31 = load i8*, i8** %2
%32 = call i32 @process_client_message(i8* %31)
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %35
35: ; preds = %30, %21
br label %17
36: ; preds = %17
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%41 = load i32*, i32** %1
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = load i32*, i32** %1
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %36
%47 = load i8*, i8** %2
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i8*, i8** %2
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %49, %46
ret void
}

LLVM IR (-O2):
@__const.process_client_connection.config_file = [29 x i8] c"parseMsg_client_training.txt\00"
@.str = [2 x i8] c"r\00"
@.str.1 = [36 x i8] c"Unable to load config file named %s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"END\00"
@.str.3 = [46 x i8] c"\0A#> Number of msgs processed from client: %d\00"
@.str.4 = [54 x i8] c"\0A#> Number of valid msgs processed from client: %d \0A\00"
define void @process_client_connection() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca [29 x i8]
%4 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = getelementptr inbounds [29 x i8], [29 x i8]* %3, i64 0, i64 0
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32 @getline(i8** %1, i64* %2, i32* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %33, label %15
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %29
%16 = phi i32 [ %30, %29 ], [ 0, %9 ]
%17 = phi i32 [ %20, %29 ], [ 0, %9 ]
%18 = load i32, i32* @stdout
%19 = call i32 @fflush(i32 %18)
%20 = add nuw nsw i32 %17, 1
%21 = load i8*, i8** %1
%22 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%23 = call i64 @strncmp(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %15
%26 = load i8*, i8** %1
%27 = call i32 @process_client_message(i8* %26)
%28 = add nsw i32 %16, 1
br label %29
29: ; preds = %25, %15
%30 = phi i32 [ %28, %25 ], [ %16, %15 ]
%31 = call i32 @getline(i8** %1, i64* %2, i32* %7)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %15
33: ; preds = %29, %9
%34 = phi i32 [ 0, %9 ], [ %20, %29 ]
%35 = phi i32 [ 0, %9 ], [ %30, %29 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%38 = call i32 @fclose(i32* %7)
%39 = load i8*, i8** %1
%40 = icmp eq i8* %39, null
br i1 %40, label %43, label %41
41: ; preds = %33
%42 = call i32 @free(i8* %39)
br label %43
43: ; preds = %41, %33
ret void
}