#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 dummy;
};

/* Variables and functions */
char *calloc(scalar_t__, int);
int /*<<< orphan*/ change_root(char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
scalar_t__ strlen(char *);
void calibrate_path() {
  char *host, *server, *path;
  struct stat s;
  server = getenv("server_home");
  host = getenv("HTTP_HOST");
  if (server && *server) {
    if (host && *host) {
      path = calloc(strlen(server) + strlen(host) + 32, sizeof(char));
      sprintf(path, "%s/domains/%s", server, host);
      if (!stat(path, &s))
        change_root(path);
      (free(path), (path) = NULL);
    } else
      change_root(server);
  }
}


x86 assembly (clang, -O0):
<calibrate_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1258 <calibrate_path+0xe8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1258 <calibrate_path+0xe8>
cmpq   $0x0,-0x8(%rbp)
je     124a <calibrate_path+0xda>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124a <calibrate_path+0xda>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x20,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe06(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%eax
jne    1234 <calibrate_path+0xc4>
mov    -0x18(%rbp),%rdi
call   1080 <change_root@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    1253 <calibrate_path+0xe3>
mov    -0x10(%rbp),%rdi
call   1080 <change_root@plt>
jmp    1258 <calibrate_path+0xe8>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calibrate_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
test   %rbx,%rbx
je     1213 <calibrate_path+0xa3>
cmpb   $0x0,(%rbx)
je     1213 <calibrate_path+0xa3>
mov    %rax,%r14
test   %rax,%rax
je     121d <calibrate_path+0xad>
cmpb   $0x0,(%r14)
je     121d <calibrate_path+0xad>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x20,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
lea    0xe3b(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1090 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1070 <stat@plt>
test   %eax,%eax
jne    1202 <calibrate_path+0x92>
mov    %r15,%rdi
call   1080 <change_root@plt>
mov    %r15,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <change_root@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [12 x i8] c"server_home\00"
@.str.1 = [10 x i8] c"HTTP_HOST\00"
@.str.2 = [14 x i8] c"%s/domains/%s\00"
define void @calibrate_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %1
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %47
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %47
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %43
17: ; preds = %14
%18 = load i8*, i8** %1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = call i64 @strlen(i8* %23)
%25 = load i8*, i8** %1
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %24, %26
%28 = add nsw i64 %27, 32
%29 = call i8* @calloc(i64 %28, i32 1)
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = load i8*, i8** %2
%32 = load i8*, i8** %1
%33 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32)
%34 = load i8*, i8** %3
%35 = call i32 @stat(i8* %34, %struct.stat* %4)
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %22
%38 = load i8*, i8** %3
%39 = call i32 @change_root(i8* %38)
br label %40
40: ; preds = %37, %22
%41 = load i8*, i8** %3
%42 = call i32 @free(i8* %41)
store i8* null, i8** %3
br label %46
43: ; preds = %17, %14
%44 = load i8*, i8** %2
%45 = call i32 @change_root(i8* %44)
br label %46
46: ; preds = %43, %40
br label %47
47: ; preds = %46, %9, %0
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [12 x i8] c"server_home\00"
@.str.1 = [10 x i8] c"HTTP_HOST\00"
@.str.2 = [14 x i8] c"%s/domains/%s\00"
define void @calibrate_path() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %3, null
br i1 %5, label %29, label %6
6: ; preds = %0
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %6
%10 = icmp eq i8* %4, null
br i1 %10, label %27, label %11
11: ; preds = %9
%12 = load i8, i8* %4
%13 = icmp eq i8 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = tail call i64 @strlen(i8* %3)
%16 = tail call i64 @strlen(i8* %4)
%17 = add i64 %15, 32
%18 = add i64 %17, %16
%19 = tail call i8* @calloc(i64 %18, i32 1)
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %4)
%21 = call i32 @stat(i8* %19, %struct.stat* %1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = tail call i32 @change_root(i8* %19)
br label %25
25: ; preds = %23, %14
%26 = tail call i32 @free(i8* %19)
br label %29
27: ; preds = %11, %9
%28 = tail call i32 @change_root(i8* %3)
br label %29
29: ; preds = %25, %27, %6, %0
ret void
}