#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;
};
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)) {
      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     1617 <main+0x417>
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,-0x17b8(%rbp)
lea    0xd1f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x17c0(%rbp)
cmpq   $0x0,-0x17c0(%rbp)
je     139c <main+0x19c>
mov    -0x17c0(%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,-0x17c8(%rbp)
lea    -0xfc0(%rbp),%rdi
lea    -0x17b0(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x17cc(%rbp)
cmpl   $0xffffffff,-0x17cc(%rbp)
je     13fc <main+0x1fc>
mov    -0x17b8(%rbp),%rax
sub    -0x17b0(%rbp),%rax
cmp    -0x17c8(%rbp),%rax
jle    1612 <main+0x412>
cmpl   $0x0,-0x17cc(%rbp)
jne    1421 <main+0x221>
lea    -0x7f0(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0xfc0(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x17a8(%rbp),%rdi
mov    0x2ba1(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x17d0(%rbp)
cmp    $0xffffffff,%eax
je     159a <main+0x39a>
lea    -0x7f0(%rbp),%rdi
mov    0x2ba3(%rip),%rax
mov    (%rax),%esi
mov    0x2b32(%rip),%rax
or     (%rax),%esi
mov    0x2b89(%rip),%rax
or     (%rax),%esi
mov    0x2b38(%rip),%rax
mov    (%rax),%edx
mov    0x2b4f(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x17d4(%rbp)
cmp    $0xffffffff,%eax
je     159a <main+0x39a>
mov    -0x17d4(%rbp),%edi
mov    0x2b3a(%rip),%rax
mov    (%rax),%esi
mov    0x2ae1(%rip),%rax
or     (%rax),%esi
call   1100 <flock@plt>
cmp    $0xffffffff,%eax
je     159a <main+0x39a>
jmp    14bc <main+0x2bc>
mov    -0x17d0(%rbp),%edi
lea    -0x1fb0(%rbp),%rsi
mov    $0x7d0,%edx
call   1090 <read@plt>
mov    %eax,-0x1fb4(%rbp)
cmp    $0x0,%eax
jle    14ff <main+0x2ff>
mov    -0x17d4(%rbp),%edi
lea    -0x1fb0(%rbp),%rsi
mov    -0x1fb4(%rbp),%edx
call   1060 <write@plt>
jmp    14bc <main+0x2bc>
mov    -0x17d0(%rbp),%edi
call   1080 <close@plt>
lea    -0xfc0(%rbp),%rdi
mov    0x2ae0(%rip),%rax
mov    (%rax),%esi
mov    0x2a6f(%rip),%rax
or     (%rax),%esi
mov    0x2ac6(%rip),%rax
or     (%rax),%esi
mov    0x2a75(%rip),%rax
mov    (%rax),%edx
mov    0x2a8c(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x17d8(%rbp)
cmp    $0xffffffff,%eax
je     1576 <main+0x376>
mov    -0x17d8(%rbp),%edi
lea    0xb39(%rip),%rsi
mov    $0xc,%edx
call   1060 <write@plt>
mov    -0x17d8(%rbp),%edi
call   1080 <close@plt>
mov    -0x17d4(%rbp),%edi
mov    0x2a1d(%rip),%rax
mov    (%rax),%esi
call   1100 <flock@plt>
mov    -0x17d4(%rbp),%edi
call   1080 <close@plt>
jmp    160d <main+0x40d>
mov    0x2a17(%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    0x29d6(%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    0xaa1(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1612 <main+0x412>
jmp    1617 <main+0x417>
mov    -0x10(%rbp),%rsi
lea    0xaaa(%rip),%rdi
call   1120 <execv@plt>
cmp    $0xffffffff,%eax
jne    1679 <main+0x479>
mov    0x2981(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1fe4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x1fe0(%rbp)
mov    0x295c(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x1fe4(%rbp),%edi
mov    -0x1fe0(%rbp),%rdx
mov    %rax,%rcx
lea    0xa64(%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
lea    0x8(%rsp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
je     1382 <main+0x182>
sub    0x8(%rsp),%rbx
cmp    %rbp,%rbx
jle    150c <main+0x30c>
test   %eax,%eax
jne    1382 <main+0x182>
lea    0x7e0(%rsp),%rdi
call   1040 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1040 <unlink@plt>
mov    0x2c47(%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    0x2c51(%rip),%rbp
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
or     0x0(%rbp),%esi
mov    0x2c36(%rip),%rax
or     (%rax),%esi
mov    0x2be5(%rip),%rax
mov    0x2bfe(%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    0x2be6(%rip),%rax
mov    0x2b8f(%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)
nopl   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 }
@.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 %160
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 %80, 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 %80, label %159
80: ; preds = %73, %66
%81 = load i32, i32* %17
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %80
%84 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%85 = call i32 @unlink(i8* %84)
%86 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%87 = call i32 @unlink(i8* %86)
br label %88
88: ; preds = %83, %80
%89 = load i8*, i8** %12
%90 = load i32, i32* @O_RDONLY
%91 = call i32 (i8*, i32, ...) @open(i8* %89, i32 %90)
store i32 %91, i32* %18
%92 = icmp ne i32 %91, -1
br i1 %92, label %93, label %148
93: ; preds = %88
%94 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%95 = load i32, i32* @O_CREAT
%96 = load i32, i32* @O_WRONLY
%97 = or i32 %95, %96
%98 = load i32, i32* @O_TRUNC
%99 = or i32 %97, %98
%100 = load i32, i32* @S_IRUSR
%101 = load i32, i32* @S_IWUSR
%102 = or i32 %100, %101
%103 = call i32 (i8*, i32, ...) @open(i8* %94, i32 %99, i32 %102)
store i32 %103, i32* %19
%104 = icmp ne i32 %103, -1
br i1 %104, label %105, label %148
105: ; preds = %93
%106 = load i32, i32* %19
%107 = load i32, i32* @LOCK_EX
%108 = load i32, i32* @LOCK_NB
%109 = or i32 %107, %108
%110 = call i32 @flock(i32 %106, i32 %109)
%111 = icmp ne i32 %110, -1
br i1 %111, label %112, label %148
112: ; preds = %105
br label %113
113: ; preds = %118, %112
%114 = load i32, i32* %18
%115 = bitcast [2000 x i8]* %21 to i8**
%116 = call i32 @read(i32 %114, i8** %115, i32 2000)
store i32 %116, i32* %22
%117 = icmp sgt i32 %116, 0
br i1 %117, label %118, label %123
118: ; preds = %113
%119 = load i32, i32* %19
%120 = getelementptr inbounds [2000 x i8], [2000 x i8]* %21, i64 0, i64 0
%121 = load i32, i32* %22
%122 = call i32 @write(i32 %119, i8* %120, i32 %121)
br label %113
123: ; preds = %113
%124 = load i32, i32* %18
%125 = call i32 @close(i32 %124)
%126 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%127 = load i32, i32* @O_CREAT
%128 = load i32, i32* @O_WRONLY
%129 = or i32 %127, %128
%130 = load i32, i32* @O_TRUNC
%131 = or i32 %129, %130
%132 = load i32, i32* @S_IRUSR
%133 = load i32, i32* @S_IWUSR
%134 = or i32 %132, %133
%135 = call i32 (i8*, i32, ...) @open(i8* %126, i32 %131, i32 %134)
store i32 %135, i32* %20
%136 = icmp ne i32 %135, -1
br i1 %136, label %137, label %142
137: ; preds = %123
%138 = load i32, i32* %20
%139 = call i32 @write(i32 %138, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 12)
%140 = load i32, i32* %20
%141 = call i32 @close(i32 %140)
br label %142
142: ; preds = %137, %123
%143 = load i32, i32* %19
%144 = load i32, i32* @LOCK_UN
%145 = call i32 @flock(i32 %143, i32 %144)
%146 = load i32, i32* %19
%147 = call i32 @close(i32 %146)
br label %158
148: ; preds = %105, %93, %88
%149 = load i32, i32* @stderr
%150 = load i8**, i8*** %5
%151 = getelementptr inbounds i8*, i8** %150, i64 0
%152 = load i8*, i8** %151
%153 = load i8*, i8** %12
%154 = getelementptr inbounds [2000 x i8], [2000 x i8]* %8, i64 0, i64 0
%155 = load i32, i32* @errno
%156 = call i8* @strerror(i32 %155)
%157 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %152, i8* %153, i8* %154, i8* %156)
br label %158
158: ; preds = %148, %142
br label %159
159: ; preds = %158, %73
br label %160
160: ; preds = %159, %38
%161 = load i8**, i8*** %5
%162 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8** %161)
%163 = icmp eq i32 %162, -1
br i1 %163, label %164, label %172
164: ; preds = %160
%165 = load i32, i32* @stderr
%166 = load i8**, i8*** %5
%167 = getelementptr inbounds i8*, i8** %166, i64 0
%168 = load i8*, i8** %167
%169 = load i32, i32* @errno
%170 = call i8* @strerror(i32 %169)
%171 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %165, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i64 0, i64 0), i8* %168, i8* %170)
br label %172
172: ; preds = %164, %160
%173 = load i32, i32* %3
ret i32 %173
}

LLVM IR (-O2):
%struct.stat = type { 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 %111, 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 %54, 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
br i1 %48, label %49, label %110
49: ; preds = %44
%50 = icmp eq i32 %42, 0
br i1 %50, label %51, label %54
51: ; preds = %49
%52 = call i32 @unlink(i8* %20)
%53 = call i32 @unlink(i8* %22)
br label %54
54: ; preds = %40, %51, %49
%55 = load i32, i32* @O_RDONLY
%56 = call i32 (i8*, i32, ...) @open(i8* %32, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %104, label %58
58: ; preds = %54
%59 = load i32, i32* @O_CREAT
%60 = load i32, i32* @O_WRONLY
%61 = or i32 %60, %59
%62 = load i32, i32* @O_TRUNC
%63 = or i32 %61, %62
%64 = load i32, i32* @S_IRUSR
%65 = load i32, i32* @S_IWUSR
%66 = or i32 %65, %64
%67 = call i32 (i8*, i32, ...) @open(i8* %20, i32 %63, i32 %66)
%68 = icmp eq i32 %67, -1
br i1 %68, label %104, label %69
69: ; preds = %58
%70 = load i32, i32* @LOCK_EX
%71 = load i32, i32* @LOCK_NB
%72 = or i32 %71, %70
%73 = call i32 @flock(i32 %67, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %104, label %75
75: ; preds = %69
%76 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%77 = bitcast [2000 x i8]* %7 to i8**
%78 = call i32 @read(i32 %56, i8** %77, i32 2000)
%79 = icmp sgt i32 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %75, %80
%81 = phi i32 [ %83, %80 ], [ %78, %75 ]
%82 = call i32 @write(i32 %67, i8* %76, i32 %81)
%83 = call i32 @read(i32 %56, i8** %77, i32 2000)
%84 = icmp sgt i32 %83, 0
br i1 %84, label %80, label %85
85: ; preds = %80, %75
%86 = call i32 @close(i32 %56)
%87 = load i32, i32* @O_CREAT
%88 = load i32, i32* @O_WRONLY
%89 = or i32 %88, %87
%90 = load i32, i32* @O_TRUNC
%91 = or i32 %89, %90
%92 = load i32, i32* @S_IRUSR
%93 = load i32, i32* @S_IWUSR
%94 = or i32 %93, %92
%95 = call i32 (i8*, i32, ...) @open(i8* %22, i32 %91, i32 %94)
%96 = icmp eq i32 %95, -1
br i1 %96, label %100, label %97
97: ; preds = %85
%98 = call i32 @write(i32 %95, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i32 12)
%99 = call i32 @close(i32 %95)
br label %100
100: ; preds = %97, %85
%101 = load i32, i32* @LOCK_UN
%102 = call i32 @flock(i32 %67, i32 %101)
%103 = call i32 @close(i32 %67)
br label %110
104: ; preds = %69, %58, %54
%105 = load i32, i32* @stderr
%106 = load i8*, i8** %1
%107 = load i32, i32* @errno
%108 = call i8* @strerror(i32 %107)
%109 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i8* %106, i8* %32, i8* %20, i8* %108)
br label %110
110: ; preds = %100, %104, %44
br label %111
111: ; preds = %110, %18
%112 = call i32 @execv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i8** %1)
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %120
114: ; preds = %111
%115 = load i32, i32* @stderr
%116 = load i8*, i8** %1
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.15, i64 0, i64 0), i8* %116, i8* %118)
br label %120
120: ; preds = %114, %111
ret i32 0
}