#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 stat {
  int st_mode;
  scalar_t__ st_size;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int S_IFDIR;
int S_IFREG;
int /*<<< orphan*/ S_IREAD;
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ sendfile(int, int, int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int serve_file(int sockfd, char *filepath, int serve) {
  int fd;
  struct stat st;
  char contentlen[32];
  stat(filepath, &st);
  if (st.st_mode & S_IFDIR) {
    char *path_append = filepath + strlen(filepath);
    sprintf(path_append, "/index.html");
    stat(filepath, &st);
  }
  if (!(st.st_mode & S_IFREG)) {
    write(sockfd, "HTTP/1.0 404 Not Found\r\n\r\n", 26);
    printf("not found\n");
    fprintf(stderr, "ERROR ");
    perror(filepath);
    return 0;
  }
  fd = open(filepath, O_RDONLY, S_IREAD);
  if (fd < 0) {
    write(sockfd, "HTTP/1.0 403 Forbidden\r\n\r\n", 26);
    printf("forbidden\n");
    fprintf(stderr, "ERROR ");
    perror(filepath);
    return 0;
  }
  write(sockfd, "HTTP/1.0 200 OK\r\n", 17);
  write(sockfd, "Server: nanows-0.0.1\r\n", 22);
  sprintf(contentlen, "Content-Length: %lli\r\n", (long long)st.st_size);
  if (serve)
    write(sockfd, contentlen, strlen(contentlen));
  write(sockfd, "\r\n", 2);
  if (serve) {
    off_t offset = 0;
    ssize_t n = 0;
    do {
      n = sendfile(sockfd, fd, &offset, st.st_size - n);
      offset += n;
      if (n < 0)
        goto error;
    } while (n > 0);
  }
  if (close(fd) < 0)
    goto error_close;
  printf("ok\n");
  return 0;
error:
  if (fd > 0)
    if (close(fd) < 0)
      goto error_close;
  perror("ERROR serving file");
  return 1;
error_close:
  perror("ERROR closing file");
  return 2;
}


x86 assembly (clang, -O0):
<serve_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x28(%rbp),%eax
mov    0x2dec(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1217 <serve_file+0x77>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x28(%rbp),%eax
mov    0x2dbf(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1276 <serve_file+0xd6>
mov    -0x8(%rbp),%edi
lea    0xdd6(%rip),%rsi
mov    $0x1a,%edx
call   1030 <write@plt>
lea    0xde0(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1450 <serve_file+0x2b0>
mov    -0x10(%rbp),%rdi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    0x2d3e(%rip),%rax
mov    (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12e8 <serve_file+0x148>
mov    -0x8(%rbp),%edi
lea    0xd91(%rip),%rsi
mov    $0x1a,%edx
call   1030 <write@plt>
lea    0xd9b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1450 <serve_file+0x2b0>
mov    -0x8(%rbp),%edi
lea    0xd6d(%rip),%rsi
mov    $0x11,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xd6b(%rip),%rsi
mov    $0x16,%edx
call   1030 <write@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd69(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1355 <serve_file+0x1b5>
mov    -0x8(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xcc5(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
cmpl   $0x0,-0x14(%rbp)
je     13d0 <serve_file+0x230>
movl   $0x0,-0x5c(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rcx
sub    -0x68(%rbp),%rcx
lea    -0x5c(%rbp),%rdx
call   1090 <sendfile@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rcx
movslq -0x5c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x5c(%rbp)
cmpq   $0x0,-0x68(%rbp)
jge    13bb <serve_file+0x21b>
jmp    13ff <serve_file+0x25f>
jmp    13c0 <serve_file+0x220>
cmpq   $0x0,-0x68(%rbp)
jg     1382 <serve_file+0x1e2>
jmp    13d0 <serve_file+0x230>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    13e7 <serve_file+0x247>
jmp    143d <serve_file+0x29d>
lea    0xcb1(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1450 <serve_file+0x2b0>
cmpl   $0x0,-0x18(%rbp)
jle    1425 <serve_file+0x285>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    1420 <serve_file+0x280>
jmp    143d <serve_file+0x29d>
jmp    1425 <serve_file+0x285>
lea    0xc77(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1450 <serve_file+0x2b0>
lea    0xc72(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serve_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%r12d
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
mov    0x10(%rsp),%eax
mov    0x2de9(%rip),%rcx
test   %eax,(%rcx)
je     1205 <serve_file+0x65>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movabs $0x682e7865646e692f,%rcx
78 2e 68
mov    %rcx,(%r14,%rax,1)
movl   $0x6c6d74,0x8(%r14,%rax,1)
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
mov    0x10(%rsp),%eax
mov    0x2dd4(%rip),%rcx
test   %eax,(%rcx)
je     1327 <serve_file+0x187>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1344 <serve_file+0x1a4>
mov    %eax,%r13d
lea    0xe09(%rip),%rsi
mov    %r12d,%edi
mov    $0x11,%edx
call   1040 <write@plt>
lea    0xe07(%rip),%rsi
mov    %r12d,%edi
mov    $0x16,%edx
call   1040 <write@plt>
mov    0x18(%rsp),%rbx
lea    0xe05(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <sprintf@plt>
test   %r15d,%r15d
je     12e5 <serve_file+0x145>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
lea    0xd82(%rip),%rsi
mov    %r12d,%edi
mov    $0x2,%edx
call   1040 <write@plt>
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
lea    0xc(%rsp),%rbp
xchg   %ax,%ax
mov    %rbx,%rcx
sub    %rax,%rcx
mov    %r12d,%edi
mov    %r13d,%esi
mov    %rbp,%rdx
call   1090 <sendfile@plt>
add    %eax,0xc(%rsp)
test   %rax,%rax
js     1383 <serve_file+0x1e3>
jne    12c0 <serve_file+0x120>
jmp    12f9 <serve_file+0x159>
lea    0xd38(%rip),%rsi
mov    %r12d,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %r13d,%edi
call   1060 <close@plt>
test   %rax,%rax
js     1395 <serve_file+0x1f5>
lea    0xda8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcde(%rip),%rsi
mov    %r12d,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
lea    0xd6d(%rip),%rdi
jmp    135f <serve_file+0x1bf>
lea    0xce3(%rip),%rsi
mov    %r12d,%edi
mov    $0x1a,%edx
call   1040 <write@plt>
lea    0xd5d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    0xcb3(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   10b0 <perror@plt>
jmp    1316 <serve_file+0x176>
test   %r13d,%r13d
jle    13ab <serve_file+0x20b>
mov    %r13d,%edi
call   1060 <close@plt>
test   %rax,%rax
jns    13ab <serve_file+0x20b>
lea    0xd00(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%eax
jmp    1318 <serve_file+0x178>
lea    0xcd7(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
jmp    1318 <serve_file+0x178>

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@S_IFDIR = global i32 0
@.str = [12 x i8] c"/index.html\00"
@S_IFREG = global i32 0
@.str.1 = [27 x i8] c"HTTP/1.0 404 Not Found\0D\0A\0D\0A\00"
@.str.2 = [11 x i8] c"not found\0A\00"
@stderr = global i32 0
@.str.3 = [7 x i8] c"ERROR \00"
@O_RDONLY = global i32 0
@S_IREAD = global i32 0
@.str.4 = [27 x i8] c"HTTP/1.0 403 Forbidden\0D\0A\0D\0A\00"
@.str.5 = [11 x i8] c"forbidden\0A\00"
@.str.6 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.7 = [23 x i8] c"Server: nanows-0.0.1\0D\0A\00"
@.str.8 = [23 x i8] c"Content-Length: %lli\0D\0A\00"
@.str.9 = [3 x i8] c"\0D\0A\00"
@.str.10 = [4 x i8] c"ok\0A\00"
@.str.11 = [19 x i8] c"ERROR serving file\00"
@.str.12 = [19 x i8] c"ERROR closing file\00"
define i32 @serve_file(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca [32 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %6
%15 = call i32 @stat(i8* %14, %struct.stat* %9)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @S_IFDIR
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %3
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %11
%27 = load i8*, i8** %11
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = load i8*, i8** %6
%30 = call i32 @stat(i8* %29, %struct.stat* %9)
br label %31
31: ; preds = %21, %3
%32 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @S_IFREG
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %45, label %37
37: ; preds = %31
%38 = load i32, i32* %5
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 26)
%40 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%43 = load i8*, i8** %6
%44 = call i32 @perror(i8* %43)
store i32 0, i32* %4
br label %124
45: ; preds = %31
%46 = load i8*, i8** %6
%47 = load i32, i32* @O_RDONLY
%48 = load i32, i32* @S_IREAD
%49 = call i32 @open(i8* %46, i32 %47, i32 %48)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %60
52: ; preds = %45
%53 = load i32, i32* %5
%54 = call i32 @write(i32 %53, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 26)
%55 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%58 = load i8*, i8** %6
%59 = call i32 @perror(i8* %58)
store i32 0, i32* %4
br label %124
60: ; preds = %45
%61 = load i32, i32* %5
%62 = call i32 @write(i32 %61, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 17)
%63 = load i32, i32* %5
%64 = call i32 @write(i32 %63, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 22)
%65 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%66 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%67 = load i64, i64* %66
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i64 %67)
%69 = load i32, i32* %7
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %77
71: ; preds = %60
%72 = load i32, i32* %5
%73 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%74 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @write(i32 %72, i8* %73, i32 %75)
br label %77
77: ; preds = %71, %60
%78 = load i32, i32* %5
%79 = call i32 @write(i32 %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2)
%80 = load i32, i32* %7
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %104
82: ; preds = %77
store i32 0, i32* %12
store i64 0, i64* %13
br label %83
83: ; preds = %100, %82
%84 = load i32, i32* %5
%85 = load i32, i32* %8
%86 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%87 = load i64, i64* %86
%88 = load i64, i64* %13
%89 = sub nsw i64 %87, %88
%90 = call i64 @sendfile(i32 %84, i32 %85, i32* %12, i64 %89)
store i64 %90, i64* %13
%91 = load i64, i64* %13
%92 = load i32, i32* %12
%93 = sext i32 %92 to i64
%94 = add nsw i64 %93, %91
%95 = trunc i64 %94 to i32
store i32 %95, i32* %12
%96 = load i64, i64* %13
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %83
br label %111
99: ; preds = %83
br label %100
100: ; preds = %99
%101 = load i64, i64* %13
%102 = icmp sgt i64 %101, 0
br i1 %102, label %83, label %103
103: ; preds = %100
br label %104
104: ; preds = %103, %77
%105 = load i32, i32* %8
%106 = call i64 @close(i32 %105)
%107 = icmp slt i64 %106, 0
br i1 %107, label %108, label %109
108: ; preds = %104
br label %122
109: ; preds = %104
%110 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %4
br label %124
111: ; preds = %98
%112 = load i32, i32* %8
%113 = icmp sgt i32 %112, 0
br i1 %113, label %114, label %120
114: ; preds = %111
%115 = load i32, i32* %8
%116 = call i64 @close(i32 %115)
%117 = icmp slt i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %114
br label %122
119: ; preds = %114
br label %120
120: ; preds = %119, %111
%121 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
store i32 1, i32* %4
br label %124
122: ; preds = %118, %108
%123 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
store i32 2, i32* %4
br label %124
124: ; preds = %122, %120, %109, %52, %37
%125 = load i32, i32* %4
ret i32 %125
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@S_IFDIR = global i32 0
@.str = [12 x i8] c"/index.html\00"
@S_IFREG = global i32 0
@.str.1 = [27 x i8] c"HTTP/1.0 404 Not Found\0D\0A\0D\0A\00"
@stderr = global i32 0
@.str.3 = [7 x i8] c"ERROR \00"
@O_RDONLY = global i32 0
@S_IREAD = global i32 0
@.str.4 = [27 x i8] c"HTTP/1.0 403 Forbidden\0D\0A\0D\0A\00"
@.str.6 = [18 x i8] c"HTTP/1.0 200 OK\0D\0A\00"
@.str.7 = [23 x i8] c"Server: nanows-0.0.1\0D\0A\00"
@.str.8 = [23 x i8] c"Content-Length: %lli\0D\0A\00"
@.str.9 = [3 x i8] c"\0D\0A\00"
@.str.11 = [19 x i8] c"ERROR serving file\00"
@.str.12 = [19 x i8] c"ERROR closing file\00"
@str = [10 x i8] c"not found\00"
@str.13 = [3 x i8] c"ok\00"
@str.14 = [10 x i8] c"forbidden\00"
define i32 @serve_file(i32 %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca [32 x i8]
%6 = alloca i32
%7 = bitcast %struct.stat* %4 to i8*
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = call i32 @stat(i8* %1, %struct.stat* %4)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @S_IFDIR
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %3
%16 = tail call i32 @strlen(i8* %1)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %18, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 12, i1 false)
%19 = call i32 @stat(i8* %1, %struct.stat* %4)
%20 = load i32, i32* %10
br label %21
21: ; preds = %15, %3
%22 = phi i32 [ %20, %15 ], [ %11, %3 ]
%23 = load i32, i32* @S_IFREG
%24 = and i32 %23, %22
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 26)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @perror(i8* %1)
br label %82
32: ; preds = %21
%33 = load i32, i32* @O_RDONLY
%34 = load i32, i32* @S_IREAD
%35 = tail call i32 @open(i8* %1, i32 %33, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 26)
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.14, i64 0, i64 0))
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = tail call i32 @perror(i8* %1)
br label %82
43: ; preds = %32
%44 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 17)
%45 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 22)
%46 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%47 = load i64, i64* %46
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i64 %47)
%49 = icmp eq i32 %2, 0
br i1 %49, label %66, label %50
50: ; preds = %43
%51 = call i32 @strlen(i8* %8)
%52 = call i32 @write(i32 %0, i8* %8, i32 %51)
%53 = call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2)
%54 = bitcast i32* %6 to i8*
store i32 0, i32* %6
br label %55
55: ; preds = %63, %50
%56 = phi i64 [ 0, %50 ], [ %58, %63 ]
%57 = sub nsw i64 %47, %56
%58 = call i64 @sendfile(i32 %0, i32 %35, i32* %6, i64 %57)
%59 = load i32, i32* %6
%60 = trunc i64 %58 to i32
%61 = add i32 %59, %60
store i32 %61, i32* %6
%62 = icmp slt i64 %58, 0
br i1 %62, label %73, label %63
63: ; preds = %55
%64 = icmp eq i64 %58, 0
br i1 %64, label %65, label %55
65: ; preds = %63
br label %68
66: ; preds = %43
%67 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 2)
br label %68
68: ; preds = %65, %66
%69 = call i64 @close(i32 %35)
%70 = icmp slt i64 %69, 0
br i1 %70, label %80, label %71
71: ; preds = %68
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.13, i64 0, i64 0))
br label %82
73: ; preds = %55
%74 = icmp sgt i32 %35, 0
br i1 %74, label %75, label %78
75: ; preds = %73
%76 = call i64 @close(i32 %35)
%77 = icmp slt i64 %76, 0
br i1 %77, label %80, label %78
78: ; preds = %75, %73
%79 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %82
80: ; preds = %75, %68
%81 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %82
82: ; preds = %80, %78, %71, %37, %26
%83 = phi i32 [ 0, %37 ], [ 2, %80 ], [ 1, %78 ], [ 0, %71 ], [ 0, %26 ]
ret i32 %83
}