#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 */
struct timeval {
  int /*<<< orphan*/ tv_sec;
};
struct stat {
  int st_mode;
  scalar_t__ st_size;
  int /*<<< orphan*/ st_mtime;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ O_RDONLY;
int S_IROTH;
int /*<<< orphan*/ S_ISREG(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ctime_r(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ envoie_404(int /*<<< orphan*/ *, char *);
scalar_t__ errno;
int /*<<< orphan*/ fin_connection(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fstat(int, struct stat *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int strlen(char *);
scalar_t__ strstr(char *, char *);
char *type_fichier(char *);
void envoie_fichier(FILE *stream, char *chemin, int keepalive) {
  char modiftime[30];
  char curtime[30];
  struct timeval tv;
  char buf[4096];
  struct stat s;
  int fd;
  if (strstr(chemin, "..")) {
    envoie_404(stream, chemin);
    return;
  }
  fd = open(chemin, O_RDONLY);
  if (fd == -1) {
    envoie_404(stream, chemin);
    return;
  }
  if (fstat(fd, &s) == -1 || !S_ISREG(s.st_mode) || !(s.st_mode & S_IROTH)) {
    close(fd);
    envoie_404(stream, chemin);
    return;
  }
  if (gettimeofday(&tv, NULL) || !ctime_r(&s.st_mtime, modiftime) ||
      !ctime_r(&tv.tv_sec, curtime)) {
    close(fd);
    envoie_404(stream, chemin);
    return;
  }
  modiftime[strlen(modiftime) - 1] = 0;
  curtime[strlen(curtime) - 1] = 0;
  fprintf(stream, "HTTP/1.1 200 OK\r\n");
  fprintf(stream, "Connection: %s\r\n", keepalive ? "keep-alive" : "close");
  fprintf(stream, "Content-length: %li\r\n", (long)s.st_size);
  fprintf(stream, "Content-type: %s\r\n", type_fichier(chemin));
  fprintf(stream, "Date: %s\r\n", curtime);
  fprintf(stream, "Last-modified: %s\r\n", modiftime);
  fprintf(stream, "\r\n");
  while (1) {
    int r = read(fd, buf, sizeof(buf)), w;
    if (r == 0)
      break;
    if (r < 0) {
      if (errno == EINTR)
        continue;
      close(fd);
      fin_connection(stream, "echec de read");
    }
    for (w = 0; w < r;) {
      int a = fwrite(buf + w, 1, r - w, stream);
      if (a <= 0) {
        if (errno == EINTR)
          continue;
        close(fd);
        fin_connection(stream, "echec de write");
      }
      w += a;
    }
  }
  close(fd);
}


x86 assembly (clang, -O0):
<envoie_fichier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1100 <strstr@plt>
cmp    $0x0,%rax
je     1222 <envoie_fichier+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <envoie_404@plt>
jmp    153a <envoie_fichier+0x35a>
mov    -0x10(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x108c(%rbp)
cmpl   $0xffffffff,-0x108c(%rbp)
jne    1259 <envoie_fichier+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <envoie_404@plt>
jmp    153a <envoie_fichier+0x35a>
mov    -0x108c(%rbp),%edi
lea    -0x1088(%rbp),%rsi
call   10f0 <fstat@plt>
cmp    $0xffffffff,%eax
je     12a0 <envoie_fichier+0xc0>
mov    -0x1088(%rbp),%edi
call   1080 <S_ISREG@plt>
cmp    $0x0,%eax
je     12a0 <envoie_fichier+0xc0>
mov    -0x1088(%rbp),%eax
mov    0x2d3b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    12bd <envoie_fichier+0xdd>
mov    -0x108c(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <envoie_404@plt>
jmp    153a <envoie_fichier+0x35a>
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
jne    1307 <envoie_fichier+0x127>
lea    -0x1088(%rbp),%rdi
add    $0x10,%rdi
lea    -0x40(%rbp),%rsi
call   1090 <ctime_r@plt>
cmp    $0x0,%eax
je     1307 <envoie_fichier+0x127>
lea    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1090 <ctime_r@plt>
cmp    $0x0,%eax
jne    1324 <envoie_fichier+0x144>
mov    -0x108c(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <envoie_404@plt>
jmp    153a <envoie_fichier+0x35a>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    0xcc7(%rip),%rdx
lea    0xcb5(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xc96(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1080(%rbp),%rdx
lea    0xc9f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10a0(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <type_fichier@plt>
mov    -0x10a0(%rbp),%rdi
mov    %rax,%rdx
lea    0xc89(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xc86(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xc7b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xc10(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x108c(%rbp),%edi
lea    -0x1070(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x1090(%rbp)
cmpl   $0x0,-0x1090(%rbp)
jne    1438 <envoie_fichier+0x258>
jmp    152f <envoie_fichier+0x34f>
cmpl   $0x0,-0x1090(%rbp)
jge    147f <envoie_fichier+0x29f>
mov    0x2b8c(%rip),%rax
mov    (%rax),%rax
mov    0x2b72(%rip),%rcx
cmp    (%rcx),%rax
jne    1464 <envoie_fichier+0x284>
jmp    1409 <envoie_fichier+0x229>
mov    -0x108c(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
lea    0xc05(%rip),%rsi
call   10a0 <fin_connection@plt>
movl   $0x0,-0x1094(%rbp)
mov    -0x1094(%rbp),%eax
cmp    -0x1090(%rbp),%eax
jge    152a <envoie_fichier+0x34a>
lea    -0x1070(%rbp),%rdi
movslq -0x1094(%rbp),%rax
add    %rax,%rdi
mov    -0x1090(%rbp),%edx
sub    -0x1094(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    %eax,-0x1098(%rbp)
cmpl   $0x0,-0x1098(%rbp)
jg     1513 <envoie_fichier+0x333>
mov    0x2af8(%rip),%rax
mov    (%rax),%rax
mov    0x2ade(%rip),%rcx
cmp    (%rcx),%rax
jne    14f8 <envoie_fichier+0x318>
jmp    1489 <envoie_fichier+0x2a9>
mov    -0x108c(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
lea    0xb7f(%rip),%rsi
call   10a0 <fin_connection@plt>
mov    -0x1098(%rbp),%eax
add    -0x1094(%rbp),%eax
mov    %eax,-0x1094(%rbp)
jmp    1489 <envoie_fichier+0x2a9>
jmp    1409 <envoie_fichier+0x229>
mov    -0x108c(%rbp),%edi
call   1050 <close@plt>
add    $0x10a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<envoie_fichier>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1068,%rsp
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xdff(%rip),%rsi
mov    %rbp,%rdi
call   1100 <strstr@plt>
test   %rax,%rax
jne    1295 <envoie_fichier+0xb5>
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1295 <envoie_fichier+0xb5>
mov    %eax,%r14d
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10f0 <fstat@plt>
cmp    $0xffffffff,%eax
je     128d <envoie_fichier+0xad>
mov    0x8(%rsp),%r12d
mov    %r12d,%edi
call   1080 <S_ISREG@plt>
test   %eax,%eax
je     128d <envoie_fichier+0xad>
mov    0x2d7c(%rip),%rax
test   %r12d,(%rax)
je     128d <envoie_fichier+0xad>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
je     12b1 <envoie_fichier+0xd1>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10b0 <envoie_404@plt>
add    $0x1068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
add    $0x1068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <envoie_404@plt>
lea    0x18(%rsp),%rdi
lea    0x40(%rsp),%r12
mov    %r12,%rsi
call   1090 <ctime_r@plt>
test   %eax,%eax
je     1268 <envoie_fichier+0x88>
mov    %rsp,%rdi
lea    0x20(%rsp),%r13
mov    %r13,%rsi
call   1090 <ctime_r@plt>
test   %eax,%eax
je     1268 <envoie_fichier+0x88>
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r12,1)
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
lea    0xd01(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
test   %r15d,%r15d
lea    0xd13(%rip),%rax
lea    0xd01(%rip),%rdx
cmove  %rax,%rdx
lea    0xce5(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdx
lea    0xcf1(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   10c0 <type_fichier@plt>
lea    0xcee(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xced(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xce4(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xc77(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
lea    0x60(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1484 <envoie_fichier+0x2a4>
mov    %eax,%ebp
mov    0x2bf8(%rip),%r13
jmp    13ee <envoie_fichier+0x20e>
mov    %r14d,%edi
lea    0x60(%rsp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1484 <envoie_fichier+0x2a4>
test   %ebp,%ebp
js     1454 <envoie_fichier+0x274>
xor    %r12d,%r12d
jmp    1408 <envoie_fichier+0x228>
nopw   0x0(%rax,%rax,1)
add    %r15d,%r12d
cmp    %r12d,%ebp
jle    13d2 <envoie_fichier+0x1f2>
movslq %r12d,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %ebp,%edx
sub    %eax,%edx
mov    $0x1,%esi
mov    %rbx,%rcx
call   10e0 <fwrite@plt>
mov    %eax,%r15d
test   %eax,%eax
jg     1400 <envoie_fichier+0x220>
mov    0x2ba6(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
je     1403 <envoie_fichier+0x223>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
lea    0xc40(%rip),%rsi
call   10a0 <fin_connection@plt>
jmp    1400 <envoie_fichier+0x220>
mov    0x2b7d(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
je     13d2 <envoie_fichier+0x1f2>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %rbx,%rdi
lea    0xc05(%rip),%rsi
call   10a0 <fin_connection@plt>
jmp    13d2 <envoie_fichier+0x1f2>
mov    %r14d,%edi
call   1050 <close@plt>
jmp    127b <envoie_fichier+0x9b>

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.stat = type { i32, i64, i32 }
@.str = [3 x i8] c"..\00"
@O_RDONLY = global i32 0
@S_IROTH = global i32 0
@.str.1 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.2 = [17 x i8] c"Connection: %s\0D\0A\00"
@.str.3 = [11 x i8] c"keep-alive\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [22 x i8] c"Content-length: %li\0D\0A\00"
@.str.6 = [19 x i8] c"Content-type: %s\0D\0A\00"
@.str.7 = [11 x i8] c"Date: %s\0D\0A\00"
@.str.8 = [20 x i8] c"Last-modified: %s\0D\0A\00"
@.str.9 = [3 x i8] c"\0D\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.10 = [14 x i8] c"echec de read\00"
@.str.11 = [15 x i8] c"echec de write\00"
define void @envoie_fichier(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [30 x i8]
%8 = alloca [30 x i8]
%9 = alloca %struct.timeval
%10 = alloca [4096 x i8]
%11 = alloca %struct.stat
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%16 = load i8*, i8** %5
%17 = call i64 @strstr(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32*, i32** %4
%21 = load i8*, i8** %5
%22 = call i32 @envoie_404(i32* %20, i8* %21)
br label %163
23: ; preds = %3
%24 = load i8*, i8** %5
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i32*, i32** %4
%31 = load i8*, i8** %5
%32 = call i32 @envoie_404(i32* %30, i8* %31)
br label %163
33: ; preds = %23
%34 = load i32, i32* %12
%35 = call i32 @fstat(i32 %34, %struct.stat* %11)
%36 = icmp eq i32 %35, -1
br i1 %36, label %48, label %37
37: ; preds = %33
%38 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @S_ISREG(i32 %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %37
%43 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%44 = load i32, i32* %43
%45 = load i32, i32* @S_IROTH
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %42, %37, %33
%49 = load i32, i32* %12
%50 = call i32 @close(i32 %49)
%51 = load i32*, i32** %4
%52 = load i8*, i8** %5
%53 = call i32 @envoie_404(i32* %51, i8* %52)
br label %163
54: ; preds = %42
%55 = call i64 @gettimeofday(%struct.timeval* %9, i32* null)
%56 = icmp ne i64 %55, 0
br i1 %56, label %67, label %57
57: ; preds = %54
%58 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 2
%59 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%60 = call i32 @ctime_r(i32* %58, i8* %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%64 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%65 = call i32 @ctime_r(i32* %63, i8* %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %73, label %67
67: ; preds = %62, %57, %54
%68 = load i32, i32* %12
%69 = call i32 @close(i32 %68)
%70 = load i32*, i32** %4
%71 = load i8*, i8** %5
%72 = call i32 @envoie_404(i32* %70, i8* %71)
br label %163
73: ; preds = %62
%74 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 %77
store i8 0, i8* %78
%79 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%80 = call i32 @strlen(i8* %79)
%81 = sub nsw i32 %80, 1
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %82
store i8 0, i8* %83
%84 = load i32*, i32** %4
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %84, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%86 = load i32*, i32** %4
%87 = load i32, i32* %6
%88 = icmp ne i32 %87, 0
%89 = zext i1 %88 to i64
%90 = select i1 %88, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0)
%91 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %90)
%92 = load i32*, i32** %4
%93 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%94 = load i64, i64* %93
%95 = call i32 (i32*, i8*, ...) @fprintf(i32* %92, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 %94)
%96 = load i32*, i32** %4
%97 = load i8*, i8** %5
%98 = call i8* @type_fichier(i8* %97)
%99 = call i32 (i32*, i8*, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %98)
%100 = load i32*, i32** %4
%101 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%102 = call i32 (i32*, i8*, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %101)
%103 = load i32*, i32** %4
%104 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%105 = call i32 (i32*, i8*, ...) @fprintf(i32* %103, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %104)
%106 = load i32*, i32** %4
%107 = call i32 (i32*, i8*, ...) @fprintf(i32* %106, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %108
108: ; preds = %73, %122, %159
%109 = load i32, i32* %12
%110 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%111 = call i32 @read(i32 %109, i8* %110, i32 4096)
store i32 %111, i32* %13
%112 = load i32, i32* %13
%113 = icmp eq i32 %112, 0
br i1 %113, label %114, label %115
114: ; preds = %108
br label %160
115: ; preds = %108
%116 = load i32, i32* %13
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %128
118: ; preds = %115
%119 = load i64, i64* @errno
%120 = load i64, i64* @EINTR
%121 = icmp eq i64 %119, %120
br i1 %121, label %122, label %123
122: ; preds = %118
br label %108
123: ; preds = %118
%124 = load i32, i32* %12
%125 = call i32 @close(i32 %124)
%126 = load i32*, i32** %4
%127 = call i32 @fin_connection(i32* %126, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %128
128: ; preds = %123, %115
store i32 0, i32* %14
br label %129
129: ; preds = %155, %149, %128
%130 = load i32, i32* %14
%131 = load i32, i32* %13
%132 = icmp slt i32 %130, %131
br i1 %132, label %133, label %159
133: ; preds = %129
%134 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%135 = load i32, i32* %14
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
%138 = load i32, i32* %13
%139 = load i32, i32* %14
%140 = sub nsw i32 %138, %139
%141 = load i32*, i32** %4
%142 = call i32 @fwrite(i8* %137, i32 1, i32 %140, i32* %141)
store i32 %142, i32* %15
%143 = load i32, i32* %15
%144 = icmp sle i32 %143, 0
br i1 %144, label %145, label %155
145: ; preds = %133
%146 = load i64, i64* @errno
%147 = load i64, i64* @EINTR
%148 = icmp eq i64 %146, %147
br i1 %148, label %149, label %150
149: ; preds = %145
br label %129
150: ; preds = %145
%151 = load i32, i32* %12
%152 = call i32 @close(i32 %151)
%153 = load i32*, i32** %4
%154 = call i32 @fin_connection(i32* %153, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %155
155: ; preds = %150, %133
%156 = load i32, i32* %15
%157 = load i32, i32* %14
%158 = add nsw i32 %157, %156
store i32 %158, i32* %14
br label %129
159: ; preds = %129
br label %108
160: ; preds = %114
%161 = load i32, i32* %12
%162 = call i32 @close(i32 %161)
br label %163
163: ; preds = %160, %67, %48, %29, %19
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.stat = type { i32, i64, i32 }
@.str = [3 x i8] c"..\00"
@O_RDONLY = global i32 0
@S_IROTH = global i32 0
@.str.1 = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.2 = [17 x i8] c"Connection: %s\0D\0A\00"
@.str.3 = [11 x i8] c"keep-alive\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [22 x i8] c"Content-length: %li\0D\0A\00"
@.str.6 = [19 x i8] c"Content-type: %s\0D\0A\00"
@.str.7 = [11 x i8] c"Date: %s\0D\0A\00"
@.str.8 = [20 x i8] c"Last-modified: %s\0D\0A\00"
@.str.9 = [3 x i8] c"\0D\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.10 = [14 x i8] c"echec de read\00"
@.str.11 = [15 x i8] c"echec de write\00"
define void @envoie_fichier(i32* %0, i8* %1, i32 %2) {
%4 = alloca [30 x i8]
%5 = alloca [30 x i8]
%6 = alloca %struct.timeval
%7 = alloca [4096 x i8]
%8 = alloca %struct.stat
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%11 = bitcast %struct.timeval* %6 to i8*
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = bitcast %struct.stat* %8 to i8*
%14 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %3
%17 = tail call i32 @envoie_404(i32* %0, i8* %1)
br label %110
18: ; preds = %3
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %1, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @envoie_404(i32* %0, i8* %1)
br label %110
24: ; preds = %18
%25 = call i32 @fstat(i32 %20, %struct.stat* %8)
%26 = icmp eq i32 %25, -1
br i1 %26, label %36, label %27
27: ; preds = %24
%28 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%29 = load i32, i32* %28
%30 = tail call i32 @S_ISREG(i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = load i32, i32* @S_IROTH
%34 = and i32 %33, %29
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32, %27, %24
%37 = tail call i32 @close(i32 %20)
%38 = tail call i32 @envoie_404(i32* %0, i8* %1)
br label %110
39: ; preds = %32
%40 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 2
%44 = call i32 @ctime_r(i32* %43, i8* %9)
%45 = icmp eq i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%48 = call i32 @ctime_r(i32* %47, i8* %10)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46, %42, %39
%51 = call i32 @close(i32 %20)
%52 = call i32 @envoie_404(i32* %0, i8* %1)
br label %110
53: ; preds = %46
%54 = call i32 @strlen(i8* %9)
%55 = add nsw i32 %54, -1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %56
store i8 0, i8* %57
%58 = call i32 @strlen(i8* %10)
%59 = add nsw i32 %58, -1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %60
store i8 0, i8* %61
%62 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 17, i64 1, i32* %0)
%63 = icmp eq i32 %2, 0
%64 = select i1 %63, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0)
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 1
%67 = load i64, i64* %66
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i64 %67)
%69 = call i8* @type_fichier(i8* %1)
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %69)
%71 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%72 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %9)
%73 = call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 2, i64 1, i32* %0)
%74 = call i32 @read(i32 %20, i8* %12, i32 4096)
%75 = icmp eq i32 %74, 0
br i1 %75, label %108, label %76
76: ; preds = %53, %105
%77 = phi i32 [ %106, %105 ], [ %74, %53 ]
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %86
79: ; preds = %76
%80 = load i64, i64* @errno
%81 = load i64, i64* @EINTR
%82 = icmp eq i64 %80, %81
br i1 %82, label %105, label %83
83: ; preds = %79
%84 = call i32 @close(i32 %20)
%85 = call i32 @fin_connection(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %105
86: ; preds = %76, %102
%87 = phi i32 [ %103, %102 ], [ 0, %76 ]
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %88
%90 = sub nsw i32 %77, %87
%91 = call i32 @fwrite(i8* %89, i32 1, i32 %90, i32* %0)
%92 = icmp slt i32 %91, 1
br i1 %92, label %93, label %100
93: ; preds = %86
%94 = load i64, i64* @errno
%95 = load i64, i64* @EINTR
%96 = icmp eq i64 %94, %95
br i1 %96, label %102, label %97
97: ; preds = %93
%98 = call i32 @close(i32 %20)
%99 = call i32 @fin_connection(i32* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %100
100: ; preds = %97, %86
%101 = add nsw i32 %91, %87
br label %102
102: ; preds = %93, %100
%103 = phi i32 [ %101, %100 ], [ %87, %93 ]
%104 = icmp sgt i32 %77, %103
br i1 %104, label %86, label %105
105: ; preds = %102, %83, %79
%106 = call i32 @read(i32 %20, i8* %12, i32 4096)
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %76
108: ; preds = %105, %53
%109 = call i32 @close(i32 %20)
br label %110
110: ; preds = %108, %50, %36, %22, %16
ret void
}