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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void *handle_client(void *data) {
  int *arg = (int *)data;
  int sockfd = *arg;
  FILE *fp;
  char msg[100];
  char line[100];
  for (;;) {
    recv(sockfd, msg, 1024, 0);
    printf("%s", msg);
    if (strncmp(msg, "quit", 4) == 0) {
      printf("Quit received\n");
      close(sockfd);
      pthread_exit(0);
    } else {
      printf("Else clause\n");
      if ((fp = fopen(msg, "r"))) {
        printf("Opening file %s\n", msg);
        while (fgets(line, 100, fp)) {
          write(sockfd, line, strlen(line));
        }
        fclose(fp);
      }
    }
  }
  pthread_exit(0);
}


x86 assembly (clang, -O0):
<handle_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x90(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    122f <handle_client+0x8f>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %edi,%edi
call   10b0 <pthread_exit@plt>
jmp    12dc <handle_client+0x13c>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x90(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12d7 <handle_client+0x137>
lea    -0x90(%rbp),%rsi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x64,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     12ce <handle_client+0x12e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10c(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x10c(%rbp),%edi
mov    -0x108(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    1273 <handle_client+0xd3>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
jmp    12dc <handle_client+0x13c>
jmp    11c0 <handle_client+0x20>

x86 assembly (clang, -O2):
<handle_client>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    (%rdi),%ebx
lea    0x70(%rsp),%r14
lea    0xe31(%rip),%r15
lea    0xe2d(%rip),%r12
mov    %rsp,%rbp
jmp    11e8 <handle_client+0x38>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1280 <handle_client+0xd0>
lea    0xdf9(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
lea    0xdd7(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     11e8 <handle_client+0x38>
mov    %rax,%r13
lea    0xdc5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
nop
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %r13,%rdx
call   10b0 <fgets@plt>
test   %rax,%rax
je     11e0 <handle_client+0x30>
mov    %rbp,%rdi
call   1080 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <write@plt>
jmp    1250 <handle_client+0xa0>
nop
lea    0xda0(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   10c0 <pthread_exit@plt>
jmp    11e8 <handle_client+0x38>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [15 x i8] c"Quit received\0A\00"
@.str.3 = [13 x i8] c"Else clause\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [17 x i8] c"Opening file %s\0A\00"
define i8* @handle_client(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = load i32, i32* %10
store i32 %11, i32* %4
br label %12
12: ; preds = %49, %1
%13 = load i32, i32* %4
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = call i32 @recv(i32 %13, i8* %14, i32 1024, i32 0)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %12
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
%25 = call i32 @pthread_exit(i32 0)
br label %49
26: ; preds = %12
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %5
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %48
31: ; preds = %26
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %39, %31
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%36 = load i32*, i32** %5
%37 = call i64 @fgets(i8* %35, i32 100, i32* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i32, i32* %4
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @write(i32 %40, i8* %41, i32 %43)
br label %34
45: ; preds = %34
%46 = load i32*, i32** %5
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %26
br label %49
49: ; preds = %48, %21
br label %12
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [5 x i8] c"quit\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [17 x i8] c"Opening file %s\0A\00"
@str = [12 x i8] c"Else clause\00"
@str.6 = [14 x i8] c"Quit received\00"
define noalias i8* @handle_client(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %21, %1
%9 = call i32 @recv(i32 %5, i8* %6, i32 1024, i32 0)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%11 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
%15 = call i32 @close(i32 %5)
%16 = call i32 @pthread_exit(i32 0)
br label %21
17: ; preds = %8
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%19 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17, %31, %13
br label %8
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%24 = call i64 @fgets(i8* %7, i32 100, i32* %19)
%25 = icmp eq i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %22, %26
%27 = call i32 @strlen(i8* %7)
%28 = call i32 @write(i32 %5, i8* %7, i32 %27)
%29 = call i64 @fgets(i8* %7, i32 100, i32* %19)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %26
31: ; preds = %26, %22
%32 = call i32 @fclose(i32* %19)
br label %21
}