#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 */

/* Variables and functions */
int chdir(char *);
int chroot(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getWebRoot(char *);
int /*<<< orphan*/ logMsg(int, char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void setupEnv() {
  char webRoot[256];
  getWebRoot(webRoot);
  int rc = chdir(webRoot);
  if (rc < 0) {
    logMsg(4, "chdir(%s) returned %d, %s", webRoot, rc, strerror(errno));
    exit(1);
  }
  rc = chroot(webRoot);
  if (rc < 0) {
    logMsg(4, "chroot(%s) returned %d, %s", webRoot, rc, strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<setupEnv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x100(%rbp),%rdi
call   1050 <getWebRoot@plt>
lea    -0x100(%rbp),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jge    11e9 <setupEnv+0x89>
lea    -0x100(%rbp),%rax
mov    %rax,-0x110(%rbp)
mov    -0x104(%rbp),%eax
mov    %eax,-0x108(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x110(%rbp),%rdx
mov    -0x108(%rbp),%ecx
mov    %eax,%r8d
mov    $0x4,%edi
lea    0xe26(%rip),%rsi
call   1060 <logMsg@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x100(%rbp),%rdi
call   1030 <chroot@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jge    125b <setupEnv+0xfb>
lea    -0x100(%rbp),%rax
mov    %rax,-0x120(%rbp)
mov    -0x104(%rbp),%eax
mov    %eax,-0x114(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x120(%rbp),%rdx
mov    -0x114(%rbp),%ecx
mov    %eax,%r8d
mov    $0x4,%edi
lea    0xdce(%rip),%rsi
call   1060 <logMsg@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setupEnv>:
push   %rbx
sub    $0x100,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <getWebRoot@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
test   %eax,%eax
js     1194 <setupEnv+0x34>
mov    %rsp,%rdi
call   1030 <chroot@plt>
test   %eax,%eax
js     11ad <setupEnv+0x4d>
add    $0x100,%rsp
pop    %rbx
ret
mov    %eax,%ebx
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe55(%rip),%rsi
jmp    11c4 <setupEnv+0x64>
mov    %eax,%ebx
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe56(%rip),%rsi
mov    %rsp,%rdx
mov    $0x4,%edi
mov    %ebx,%ecx
mov    %eax,%r8d
call   1060 <logMsg@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"chdir(%s) returned %d, %s\00"
@errno = global i32 0
@.str.1 = [27 x i8] c"chroot(%s) returned %d, %s\00"
define void @setupEnv() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = call i32 @getWebRoot(i8* %3)
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = call i32 @chdir(i8* %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = load i32, i32* %2
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11, i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%18 = call i32 @chroot(i8* %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%23 = load i32, i32* %2
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %23, i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"chdir(%s) returned %d, %s\00"
@errno = global i32 0
@.str.1 = [27 x i8] c"chroot(%s) returned %d, %s\00"
define void @setupEnv() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @getWebRoot(i8* %2)
%4 = call i32 @chdir(i8* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %4, i32 %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 @chroot(i8* %2)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @logMsg(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %12, i32 %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %11
ret void
}