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

/* Variables and functions */
int /*<<< orphan*/ envoie_fichier(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ envoie_live_data(int /*<<< orphan*/ *, char *, int);
scalar_t__ errno;
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fin_connection(int /*<<< orphan*/ *, char *);
int lit_en_tetes(int /*<<< orphan*/ *);
int /*<<< orphan*/ lit_get(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ setlinebuf(int /*<<< orphan*/ *);
scalar_t__ strncmp(char *, char *, int);
void *traite_connection(void *arg) {
  int socket = (int)arg;
  FILE *stream = fdopen(socket, "r+");
  char url[4096];
  int keepalive = 1;
  errno = 0;
  setlinebuf(stream);
  while (keepalive) {
    lit_get(stream, url, sizeof(url));
    keepalive = lit_en_tetes(stream);
    if (strncmp("hc_", url, 3) == 0) {
      envoie_live_data(stream, url, keepalive);
    } else {
      envoie_fichier(stream, url, keepalive);
    }
  }
  fin_connection(stream, "ok");
  return NULL;
}


x86 assembly (clang, -O0):
<traite_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0xe60(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1024(%rbp)
mov    0x2e26(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1050 <setlinebuf@plt>
cmpl   $0x0,-0x1024(%rbp)
je     1253 <traite_connection+0xd3>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <lit_get@plt>
mov    -0x18(%rbp),%rdi
call   1060 <lit_en_tetes@plt>
mov    %eax,-0x1024(%rbp)
lea    -0x1020(%rbp),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1238 <traite_connection+0xb8>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1024(%rbp),%edx
call   10a0 <envoie_live_data@plt>
jmp    124e <traite_connection+0xce>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1024(%rbp),%edx
call   1030 <envoie_fichier@plt>
jmp    11ca <traite_connection+0x4a>
mov    -0x18(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1070 <fin_connection@plt>
xor    %eax,%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traite_connection>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
lea    0xe6c(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,%rbx
mov    0x2e3d(%rip),%rax
movq   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <setlinebuf@plt>
mov    %rsp,%r14
lea    0xe47(%rip),%r15
jmp    11c9 <traite_connection+0x49>
xchg   %ax,%ax
call   1030 <envoie_fichier@plt>
test   %ebp,%ebp
je     1209 <traite_connection+0x89>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1090 <lit_get@plt>
mov    %rbx,%rdi
call   1060 <lit_en_tetes@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
test   %rax,%rax
jne    11c0 <traite_connection+0x40>
call   10a0 <envoie_live_data@plt>
test   %ebp,%ebp
jne    11c9 <traite_connection+0x49>
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fin_connection@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@errno = global i64 0
@.str.1 = [4 x i8] c"hc_\00"
@.str.2 = [3 x i8] c"ok\00"
define i8* @traite_connection(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [4096 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
store i32 1, i32* %6
store i64 0, i64* @errno
%11 = load i32*, i32** %4
%12 = call i32 @setlinebuf(i32* %11)
br label %13
13: ; preds = %35, %1
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %36
16: ; preds = %13
%17 = load i32*, i32** %4
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i32 @lit_get(i32* %17, i8* %18, i32 4096)
%20 = load i32*, i32** %4
%21 = call i32 @lit_en_tetes(i32* %20)
store i32 %21, i32* %6
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%23 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load i32*, i32** %4
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* %6
%29 = call i32 @envoie_live_data(i32* %26, i8* %27, i32 %28)
br label %35
30: ; preds = %16
%31 = load i32*, i32** %4
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* %6
%34 = call i32 @envoie_fichier(i32* %31, i8* %32, i32 %33)
br label %35
35: ; preds = %30, %25
br label %13
36: ; preds = %13
%37 = load i32*, i32** %4
%38 = call i32 @fin_connection(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i8* null
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@errno = global i64 0
@.str.1 = [4 x i8] c"hc_\00"
@.str.2 = [3 x i8] c"ok\00"
define noalias i8* @traite_connection(i8* %0) {
%2 = alloca [4096 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32* @fdopen(i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
store i64 0, i64* @errno
%7 = tail call i32 @setlinebuf(i32* %5)
br label %8
8: ; preds = %1, %17
%9 = call i32 @lit_get(i32* %5, i8* %6, i32 4096)
%10 = call i32 @lit_en_tetes(i32* %5)
%11 = call i64 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @envoie_live_data(i32* %5, i8* %6, i32 %10)
br label %17
15: ; preds = %8
%16 = call i32 @envoie_fichier(i32* %5, i8* %6, i32 %10)
br label %17
17: ; preds = %15, %13
%18 = icmp eq i32 %10, 0
br i1 %18, label %19, label %8
19: ; preds = %17
%20 = call i32 @fin_connection(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i8* null
}