#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 long time_t;
struct stat {
  long st_mtime;
  scalar_t__ st_size;
};
struct passwd {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int LOCK_EX;
int LOCK_NB;
int LOCK_UN;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int execv(char *, char **);
int flock(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
char *getenv(char *);
int open(char *, int, ...);
int read(int, char **, int);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *strtok(char *, char *);
long time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  struct passwd *pw = NULL;
  char *remote_user = getenv("WEBDAV_USER");
  if (remote_user == NULL)
    remote_user = getenv("REDIRECT_WEBDAV_USER");
  if (remote_user == NULL)
    remote_user = getenv("REMOTE_USER");
  if (remote_user == NULL)
    remote_user = getenv("REDIRECT_REMOTE_USER");
  char dstfilename[2000];
  snprintf(dstfilename, 2000, "/tmp/krb5cc_webdavcgi_%s", remote_user);
  char dstmtimefilename[2000];
  snprintf(dstmtimefilename, 2000, "/tmp/krb5cc_webdavcgi_age_%s", remote_user);
  char *krbticket = getenv("KRB5CCNAME");
  char krbenv[2000];
  snprintf(krbenv, 2000, "FILE:%s", dstfilename);
  setenv("KRB5CCNAME", krbenv, 1);
  setenv("WEBDAVISWRAPPED", "TRUE", 1);
  if (krbticket != NULL) {
    strtok(krbticket, ":");
    char *srcfilename = strtok(NULL, ":");
    struct stat dststat;
    time_t seconds = time(NULL);
    char *tlt = getenv("TICKET_LIFETIME");
    long ticket_lifetime = tlt != NULL ? atol(tlt) : 28800;
    int exists = stat(dstmtimefilename, &dststat);
    if ((exists == -1) || (seconds - dststat.st_mtime > ticket_lifetime) ||
        (dststat.st_size == 0)) {
      if (exists == 0) {
        unlink(dstfilename);
        unlink(dstmtimefilename);
      }
      int src, dst, dstmtime;
      if ((src = open(srcfilename, O_RDONLY)) != -1 &&
          (dst = open(dstfilename, O_CREAT | O_WRONLY | O_TRUNC,
                      S_IRUSR | S_IWUSR)) != -1 &&
          flock(dst, LOCK_EX | LOCK_NB) != -1) {
        char buf[2000];
        ssize_t count;
        while ((count = read(src, &buf, 2000)) > 0)
          write(dst, buf, count);
        close(src);
        if ((dstmtime = open(dstmtimefilename, O_CREAT | O_WRONLY | O_TRUNC,
                             S_IRUSR | S_IWUSR)) != -1) {
          write(dstmtime, "age checking", 12);
          close(dstmtime);
        }
        flock(dst, LOCK_UN);
        close(dst);
      } else {
        fprintf(stderr, "%s: ERROR: Cannot copy %s to %s: %s\n", argv[0],
                srcfilename, dstfilename, strerror(errno));
      }
    }
  }
  if (execv("webdav.pl", argv) == -1)
    fprintf(stderr, "%s: ERROR: Cannot execute webdav.pl: %s\n", argv[0],
            strerror(errno));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1ff0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xde1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    124c <main+0x4c>
lea    0xdbd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1267 <main+0x67>
lea    0xdc0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1282 <main+0x82>
lea    0xd9c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
lea    -0x7f0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x7d0,%esi
lea    0xd91(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0xfc0(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x7d0,%esi
lea    0xd8e(%rip),%rdx
call   1070 <snprintf@plt>
lea    0xd9f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0xfc8(%rbp)
lea    -0x17a0(%rbp),%rdi
lea    -0x7f0(%rbp),%rcx
mov    $0x7d0,%esi
lea    0xd84(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x17a0(%rbp),%rsi
lea    0xd66(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    0xd68(%rip),%rdi
lea    0xd71(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
cmpq   $0x0,-0xfc8(%rbp)
je     1625 <main+0x425>
mov    -0xfc8(%rbp),%rdi
lea    0xd50(%rip),%rsi
call   10f0 <strtok@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd40(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x17a8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %rax,-0x17c0(%rbp)
lea    0xd1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x17c8(%rbp)
cmpq   $0x0,-0x17c8(%rbp)
je     139c <main+0x19c>
mov    -0x17c8(%rbp),%rdi
call   10d0 <atol@plt>
mov    %eax,-0x1fb8(%rbp)
jmp    13ac <main+0x1ac>
mov    $0x7080,%eax
mov    %eax,-0x1fb8(%rbp)
jmp    13ac <main+0x1ac>
mov    -0x1fb8(%rbp),%eax
cltq
mov    %rax,-0x17d0(%rbp)
lea    -0xfc0(%rbp),%rdi
lea    -0x17b8(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x17d4(%rbp)
cmpl   $0xffffffff,-0x17d4(%rbp)
je     140a <main+0x20a>
mov    -0x17c0(%rbp),%rax
sub    -0x17b8(%rbp),%rax
cmp    -0x17d0(%rbp),%rax
jg     140a <main+0x20a>
cmpq   $0x0,-0x17b0(%rbp)
jne    1620 <main+0x420>
cmpl   $0x0,-0x17d4(%rbp)
jne    142f <main+0x22f>
lea    -0x7f0(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0xfc0(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x17a8(%rbp),%rdi
mov    0x2b93(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x17d8(%rbp)
cmp    $0xffffffff,%eax
je     15a8 <main+0x3a8>
lea    -0x7f0(%rbp),%rdi
mov    0x2b95(%rip),%rax
mov    (%rax),%esi
mov    0x2b24(%rip),%rax
or     (%rax),%esi
mov    0x2b7b(%rip),%rax
or     (%rax),%esi
mov    0x2b2a(%rip),%rax
mov    (%rax),%edx
mov    0x2b41(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x17dc(%rbp)
cmp    $0xffffffff,%eax
je     15a8 <main+0x3a8>
mov    -0x17dc(%rbp),%edi
mov    0x2b2c(%rip),%rax
mov    (%rax),%esi
mov    0x2ad3(%rip),%rax
or     (%rax),%esi
call   1100 <flock@plt>
cmp    $0xffffffff,%eax
je     15a8 <main+0x3a8>
jmp    14ca <main+0x2ca>
mov    -0x17d8(%rbp),%edi
lea    -0x1fb0(%rbp),%rsi
mov    $0x7d0,%edx
call   1090 <read@plt>
mov    %eax,-0x1fb4(%rbp)
cmp    $0x0,%eax
jle    150d <main+0x30d>
mov    -0x17dc(%rbp),%edi
lea    -0x1fb0(%rbp),%rsi
mov    -0x1fb4(%rbp),%edx
call   1060 <write@plt>
jmp    14ca <main+0x2ca>
mov    -0x17d8(%rbp),%edi
call   1080 <close@plt>
lea    -0xfc0(%rbp),%rdi
mov    0x2ad2(%rip),%rax
mov    (%rax),%esi
mov    0x2a61(%rip),%rax
or     (%rax),%esi
mov    0x2ab8(%rip),%rax
or     (%rax),%esi
mov    0x2a67(%rip),%rax
mov    (%rax),%edx
mov    0x2a7e(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x17e0(%rbp)
cmp    $0xffffffff,%eax
je     1584 <main+0x384>
mov    -0x17e0(%rbp),%edi
lea    0xb2b(%rip),%rsi
mov    $0xc,%edx
call   1060 <write@plt>
mov    -0x17e0(%rbp),%edi
call   1080 <close@plt>
mov    -0x17dc(%rbp),%edi
mov    0x2a0f(%rip),%rax
mov    (%rax),%esi
call   1100 <flock@plt>
mov    -0x17dc(%rbp),%edi
call   1080 <close@plt>
jmp    161b <main+0x41b>
mov    0x2a09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1fd4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1fd0(%rbp)
mov    -0x17a8(%rbp),%rax
mov    %rax,-0x1fc8(%rbp)
lea    -0x7f0(%rbp),%rax
mov    %rax,-0x1fc0(%rbp)
mov    0x29c8(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x1fd4(%rbp),%edi
mov    -0x1fd0(%rbp),%rdx
mov    -0x1fc8(%rbp),%rcx
mov    -0x1fc0(%rbp),%r8
mov    %rax,%r9
lea    0xa93(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1620 <main+0x420>
jmp    1625 <main+0x425>
mov    -0x10(%rbp),%rsi
lea    0xa9c(%rip),%rdi
call   1120 <execv@plt>
cmp    $0xffffffff,%eax
jne    1687 <main+0x487>
mov    0x2973(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1fe4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1fe0(%rbp)
mov    0x294e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x1fe4(%rbp),%edi
mov    -0x1fe0(%rbp),%rdx
mov    %rax,%rcx
lea    0xa56(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x1ff0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
mov    %rsi,%r14
lea    0xdee(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    125f <main+0x5f>
lea    0xdd1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    125f <main+0x5f>
lea    0xddb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    125f <main+0x5f>
lea    0xdbe(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xdc4(%rip),%rdx
lea    0x7e0(%rsp),%r15
mov    %r15,%rdi
mov    $0x7d0,%esi
mov    %rbx,%rcx
call   1070 <snprintf@plt>
lea    0xdbe(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x7d0,%esi
mov    %rbx,%rcx
call   1070 <snprintf@plt>
lea    0xdc2(%rip),%r12
mov    %r12,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xdbb(%rip),%rdx
lea    0x1780(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x7d0,%esi
mov    %r15,%rcx
call   1070 <snprintf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
lea    0xd94(%rip),%rdi
lea    0xd9d(%rip),%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
test   %rbx,%rbx
je     150c <main+0x30c>
lea    0xd88(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <strtok@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   10f0 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
call   10c0 <time@plt>
mov    %rax,%rbx
lea    0xd61(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1340 <main+0x140>
mov    %rax,%rdi
call   10d0 <atol@plt>
movslq %eax,%rbp
jmp    1345 <main+0x145>
mov    $0x7080,%ebp
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     1387 <main+0x187>
sub    (%rsp),%rbx
cmp    %rbp,%rbx
jg     136c <main+0x16c>
cmpq   $0x0,0x8(%rsp)
jne    150c <main+0x30c>
test   %eax,%eax
jne    1387 <main+0x187>
lea    0x7e0(%rsp),%rdi
call   1040 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     14d1 <main+0x2d1>
mov    %eax,%ebx
mov    0x2c4c(%rip),%rbp
mov    0x2bdd(%rip),%rax
mov    (%rax),%esi
or     0x0(%rbp),%esi
mov    0x2c31(%rip),%rax
or     (%rax),%esi
mov    0x2be0(%rip),%rax
mov    0x2bf9(%rip),%r13
mov    0x0(%r13),%edx
or     (%rax),%edx
lea    0x7e0(%rsp),%rdi
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     14d1 <main+0x2d1>
mov    %eax,%r12d
mov    0x2be1(%rip),%rax
mov    0x2b8a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r12d,%edi
call   1100 <flock@plt>
cmp    $0xffffffff,%eax
je     14d1 <main+0x2d1>
mov    %rbp,%r15
lea    0xfb0(%rsp),%rsi
mov    %ebx,%edi
mov    $0x7d0,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1460 <main+0x260>
lea    0xfb0(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x7d0,%edx
call   1090 <read@plt>
test   %eax,%eax
jg     1440 <main+0x240>
mov    %ebx,%edi
call   1080 <close@plt>
mov    0x2b22(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    0x2b76(%rip),%rax
or     (%rax),%esi
mov    0x0(%r13),%edx
mov    0x2b21(%rip),%rax
or     (%rax),%edx
lea    0x10(%rsp),%rdi
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     14b6 <main+0x2b6>
mov    %eax,%ebx
lea    0xbf7(%rip),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1060 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    0x2ae3(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1100 <flock@plt>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    150c <main+0x30c>
mov    0x2ae0(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x2acc(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xbb5(%rip),%rsi
lea    0x7e0(%rsp),%r8
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %rax,%r9
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xbb9(%rip),%rdi
mov    %r14,%rsi
call   1120 <execv@plt>
cmp    $0xffffffff,%eax
jne    1550 <main+0x350>
mov    0x2a91(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rbp
mov    0x2a7d(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xb95(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %eax,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
%struct.stat = type { i64, i64 }
@.str = [12 x i8] c"WEBDAV_USER\00"
@.str.1 = [21 x i8] c"REDIRECT_WEBDAV_USER\00"
@.str.2 = [12 x i8] c"REMOTE_USER\00"
@.str.3 = [21 x i8] c"REDIRECT_REMOTE_USER\00"
@.str.4 = [25 x i8] c"/tmp/krb5cc_webdavcgi_%s\00"
@.str.5 = [29 x i8] c"/tmp/krb5cc_webdavcgi_age_%s\00"
@.str.6 = [11 x i8] c"KRB5CCNAME\00"
@.str.7 = [8 x i8] c"FILE:%s\00"
@.str.8 = [16 x i8] c"WEBDAVISWRAPPED\00"
@.str.9 = [5 x i8] c"TRUE\00"
@.str.10 = [2 x i8] c":\00"
@.str.11 = [16 x i8] c"TICKET_LIFETIME\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@.str.12 = [13 x i8] c"age checking\00"
@LOCK_UN = global i32 0
@stderr = global i32 0
@.str.13 = [37 x i8] c"%s: ERROR: Cannot copy %s to %s: %s\0A\00"
@errno = global i32 0
@.str.14 = [10 x i8] c"webdav.pl\00"
@.str.15 = [41 x i8] c"%s: ERROR: Cannot execute webdav.pl: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.passwd*
%7 = alloca i8*
%8 = alloca [2000 x i8]
%9 = alloca [2000 x i8]
%10 = alloca i8*
%11 = alloca [2000 x i8]
%12 = alloca i8*
%13 = alloca %struct.stat
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca [2000 x i8]
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.passwd* null, %struct.passwd** %6
%23 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %2
%27 = call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %7
br label %28
28: ; preds = %26, %2
%29 = load i8*, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8* %32, i8** %7
br label %33
33: ; preds = %31, %28
%34 = load i8*, i8** %7
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i8* %37, i8** %7
br label %38
38: ; preds = %36, %33
%39 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%40 = load i8*, i8** %7
%41 = call i32 @snprintf(i8* %39, i32 2000, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%43 = load i8*, i8** %7
%44 = call i32 @snprintf(i8* %42, i32 2000, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
store i8* %45, i8** %10
%46 = getelementptr inbounds [2000 x i8], [2000 x i8]* %11, i64 0, i64 0
%47 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%48 = call i32 @snprintf(i8* %46, i32 2000, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [2000 x i8], [2000 x i8]* %11, i64 0, i64 0
%50 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %49, i32 1)
%51 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 1)
%52 = load i8*, i8** %10
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %164
54: ; preds = %38
%55 = load i8*, i8** %10
%56 = call i8* @strtok(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%57 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i8* %57, i8** %12
%58 = call i64 @time(i32* null)
store i64 %58, i64* %14
%59 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
store i8* %59, i8** %15
%60 = load i8*, i8** %15
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %54
%63 = load i8*, i8** %15
%64 = call i32 @atol(i8* %63)
br label %66
65: ; preds = %54
br label %66
66: ; preds = %65, %62
%67 = phi i32 [ %64, %62 ], [ 28800, %65 ]
%68 = sext i32 %67 to i64
store i64 %68, i64* %16
%69 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%70 = call i32 @stat(i8* %69, %struct.stat* %13)
store i32 %70, i32* %17
%71 = load i32, i32* %17
%72 = icmp eq i32 %71, -1
br i1 %72, label %84, label %73
73: ; preds = %66
%74 = load i64, i64* %14
%75 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%76 = load i64, i64* %75
%77 = sub nsw i64 %74, %76
%78 = load i64, i64* %16
%79 = icmp sgt i64 %77, %78
br i1 %79, label %84, label %80
80: ; preds = %73
%81 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%82 = load i64, i64* %81
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %163
84: ; preds = %80, %73, %66
%85 = load i32, i32* %17
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %92
87: ; preds = %84
%88 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%89 = call i32 @unlink(i8* %88)
%90 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%91 = call i32 @unlink(i8* %90)
br label %92
92: ; preds = %87, %84
%93 = load i8*, i8** %12
%94 = load i32, i32* @O_RDONLY
%95 = call i32 (i8*, i32, ...) @open(i8* %93, i32 %94)
store i32 %95, i32* %18
%96 = icmp ne i32 %95, -1
br i1 %96, label %97, label %152
97: ; preds = %92
%98 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%99 = load i32, i32* @O_CREAT
%100 = load i32, i32* @O_WRONLY
%101 = or i32 %99, %100
%102 = load i32, i32* @O_TRUNC
%103 = or i32 %101, %102
%104 = load i32, i32* @S_IRUSR
%105 = load i32, i32* @S_IWUSR
%106 = or i32 %104, %105
%107 = call i32 (i8*, i32, ...) @open(i8* %98, i32 %103, i32 %106)
store i32 %107, i32* %19
%108 = icmp ne i32 %107, -1
br i1 %108, label %109, label %152
109: ; preds = %97
%110 = load i32, i32* %19
%111 = load i32, i32* @LOCK_EX
%112 = load i32, i32* @LOCK_NB
%113 = or i32 %111, %112
%114 = call i32 @flock(i32 %110, i32 %113)
%115 = icmp ne i32 %114, -1
br i1 %115, label %116, label %152
116: ; preds = %109
br label %117
117: ; preds = %122, %116
%118 = load i32, i32* %18
%119 = bitcast [2000 x i8]* %21 to i8**
%120 = call i32 @read(i32 %118, i8** %119, i32 2000)
store i32 %120, i32* %22
%121 = icmp sgt i32 %120, 0
br i1 %121, label %122, label %127
122: ; preds = %117
%123 = load i32, i32* %19
%124 = getelementptr inbounds [2000 x i8], [2000 x i8]* %21, i64 0, i64 0
%125 = load i32, i32* %22
%126 = call i32 @write(i32 %123, i8* %124, i32 %125)
br label %117
127: ; preds = %117
%128 = load i32, i32* %18
%129 = call i32 @close(i32 %128)
%130 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%131 = load i32, i32* @O_CREAT
%132 = load i32, i32* @O_WRONLY
%133 = or i32 %131, %132
%134 = load i32, i32* @O_TRUNC
%135 = or i32 %133, %134
%136 = load i32, i32* @S_IRUSR
%137 = load i32, i32* @S_IWUSR
%138 = or i32 %136, %137
%139 = call i32 (i8*, i32, ...) @open(i8* %130, i32 %135, i32 %138)
store i32 %139, i32* %20
%140 = icmp ne i32 %139, -1
br i1 %140, label %141, label %146
141: ; preds = %127
%142 = load i32, i32* %20
%143 = call i32 @write(i32 %142, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 12)
%144 = load i32, i32* %20
%145 = call i32 @close(i32 %144)
br label %146
146: ; preds = %141, %127
%147 = load i32, i32* %19
%148 = load i32, i32* @LOCK_UN
%149 = call i32 @flock(i32 %147, i32 %148)
%150 = load i32, i32* %19
%151 = call i32 @close(i32 %150)
br label %162
152: ; preds = %109, %97, %92
%153 = load i32, i32* @stderr
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 0
%156 = load i8*, i8** %155
%157 = load i8*, i8** %12
%158 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%159 = load i32, i32* @errno
%160 = call i8* @strerror(i32 %159)
%161 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %156, i8* %157, i8* %158, i8* %160)
br label %162
162: ; preds = %152, %146
br label %163
163: ; preds = %162, %80
br label %164
164: ; preds = %163, %38
%165 = load i8**, i8*** %5
%166 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8** %165)
%167 = icmp eq i32 %166, -1
br i1 %167, label %168, label %176
168: ; preds = %164
%169 = load i32, i32* @stderr
%170 = load i8**, i8*** %5
%171 = getelementptr inbounds i8*, i8** %170, i64 0
%172 = load i8*, i8** %171
%173 = load i32, i32* @errno
%174 = call i8* @strerror(i32 %173)
%175 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i64 0, i64 0), i8* %172, i8* %174)
br label %176
176: ; preds = %168, %164
%177 = load i32, i32* %3
ret i32 %177
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
%struct.passwd = type { i32 }
@.str = [12 x i8] c"WEBDAV_USER\00"
@.str.1 = [21 x i8] c"REDIRECT_WEBDAV_USER\00"
@.str.2 = [12 x i8] c"REMOTE_USER\00"
@.str.3 = [21 x i8] c"REDIRECT_REMOTE_USER\00"
@.str.4 = [25 x i8] c"/tmp/krb5cc_webdavcgi_%s\00"
@.str.5 = [29 x i8] c"/tmp/krb5cc_webdavcgi_age_%s\00"
@.str.6 = [11 x i8] c"KRB5CCNAME\00"
@.str.7 = [8 x i8] c"FILE:%s\00"
@.str.8 = [16 x i8] c"WEBDAVISWRAPPED\00"
@.str.9 = [5 x i8] c"TRUE\00"
@.str.10 = [2 x i8] c":\00"
@.str.11 = [16 x i8] c"TICKET_LIFETIME\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@.str.12 = [13 x i8] c"age checking\00"
@LOCK_UN = global i32 0
@stderr = global i32 0
@.str.13 = [37 x i8] c"%s: ERROR: Cannot copy %s to %s: %s\0A\00"
@errno = global i32 0
@.str.14 = [10 x i8] c"webdav.pl\00"
@.str.15 = [41 x i8] c"%s: ERROR: Cannot execute webdav.pl: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2000 x i8]
%4 = alloca [2000 x i8]
%5 = alloca [2000 x i8]
%6 = alloca %struct.stat
%7 = alloca [2000 x i8]
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %2, %10, %16, %13
%19 = phi i8* [ %17, %16 ], [ %14, %13 ], [ %11, %10 ], [ %8, %2 ]
%20 = getelementptr inbounds [2000 x i8], [2000 x i8]* %3, i64 0, i64 0
%21 = call i32 @snprintf(i8* %20, i32 2000, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%22 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%23 = call i32 @snprintf(i8* %22, i32 2000, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %19)
%24 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%25 = getelementptr inbounds [2000 x i8], [2000 x i8]* %5, i64 0, i64 0
%26 = call i32 @snprintf(i8* %25, i32 2000, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %20)
%27 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %25, i32 1)
%28 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 1)
%29 = icmp eq i8* %24, null
br i1 %29, label %115, label %30
30: ; preds = %18
%31 = call i8* @strtok(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%33 = bitcast %struct.stat* %6 to i8*
%34 = call i64 @time(i32* null)
%35 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%36 = icmp eq i8* %35, null
br i1 %36, label %40, label %37
37: ; preds = %30
%38 = call i32 @atol(i8* %35)
%39 = sext i32 %38 to i64
br label %40
40: ; preds = %30, %37
%41 = phi i64 [ %39, %37 ], [ 28800, %30 ]
%42 = call i32 @stat(i8* %22, %struct.stat* %6)
%43 = icmp eq i32 %42, -1
br i1 %43, label %58, label %44
44: ; preds = %40
%45 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%46 = load i64, i64* %45
%47 = sub nsw i64 %34, %46
%48 = icmp sgt i64 %47, %41
%49 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 1
%50 = load i64, i64* %49
%51 = icmp eq i64 %50, 0
%52 = select i1 %48, i1 true, i1 %51
br i1 %52, label %53, label %114
53: ; preds = %44
%54 = icmp eq i32 %42, 0
br i1 %54, label %55, label %58
55: ; preds = %53
%56 = call i32 @unlink(i8* %20)
%57 = call i32 @unlink(i8* %22)
br label %58
58: ; preds = %40, %55, %53
%59 = load i32, i32* @O_RDONLY
%60 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %108, label %62
62: ; preds = %58
%63 = load i32, i32* @O_CREAT
%64 = load i32, i32* @O_WRONLY
%65 = or i32 %64, %63
%66 = load i32, i32* @O_TRUNC
%67 = or i32 %65, %66
%68 = load i32, i32* @S_IRUSR
%69 = load i32, i32* @S_IWUSR
%70 = or i32 %69, %68
%71 = call i32 (i8*, i32, ...) @open(i8* %20, i32 %67, i32 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %108, label %73
73: ; preds = %62
%74 = load i32, i32* @LOCK_EX
%75 = load i32, i32* @LOCK_NB
%76 = or i32 %75, %74
%77 = call i32 @flock(i32 %71, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %108, label %79
79: ; preds = %73
%80 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%81 = bitcast [2000 x i8]* %7 to i8**
%82 = call i32 @read(i32 %60, i8** %81, i32 2000)
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %79, %84
%85 = phi i32 [ %87, %84 ], [ %82, %79 ]
%86 = call i32 @write(i32 %71, i8* %80, i32 %85)
%87 = call i32 @read(i32 %60, i8** %81, i32 2000)
%88 = icmp sgt i32 %87, 0
br i1 %88, label %84, label %89
89: ; preds = %84, %79
%90 = call i32 @close(i32 %60)
%91 = load i32, i32* @O_CREAT
%92 = load i32, i32* @O_WRONLY
%93 = or i32 %92, %91
%94 = load i32, i32* @O_TRUNC
%95 = or i32 %93, %94
%96 = load i32, i32* @S_IRUSR
%97 = load i32, i32* @S_IWUSR
%98 = or i32 %97, %96
%99 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %95, i32 %98)
%100 = icmp eq i32 %99, -1
br i1 %100, label %104, label %101
101: ; preds = %89
%102 = call i32 @write(i32 %99, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 12)
%103 = call i32 @close(i32 %99)
br label %104
104: ; preds = %101, %89
%105 = load i32, i32* @LOCK_UN
%106 = call i32 @flock(i32 %71, i32 %105)
%107 = call i32 @close(i32 %71)
br label %114
108: ; preds = %73, %62, %58
%109 = load i32, i32* @stderr
%110 = load i8*, i8** %1
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %110, i8* %32, i8* %20, i8* %112)
br label %114
114: ; preds = %104, %108, %44
br label %115
115: ; preds = %114, %18
%116 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8** %1)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %124
118: ; preds = %115
%119 = load i32, i32* @stderr
%120 = load i8*, i8** %1
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i64 0, i64 0), i8* %120, i8* %122)
br label %124
124: ; preds = %118, %115
ret i32 0
}