#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 /*<<< orphan*/ LOG_ERR;
scalar_t__ chdir(char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char const *,
                          int /*<<< orphan*/, int /*<<< orphan*/);
int set_run_directory(const char *run_directory) {
  if ((chdir(run_directory)) < 0) {
    syslog(LOG_ERR, "failed to change directory to %s, code %d (%s)",
           run_directory, errno, strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<set_run_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    11a2 <set_run_directory+0x72>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    %eax,%r8d
lea    0xe6f(%rip),%rsi
call   1040 <syslog@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <set_run_directory+0x79>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_run_directory>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <chdir@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jns    117c <set_run_directory+0x4c>
mov    0x2e80(%rip),%rax
mov    (%rax),%r14d
mov    0x2e86(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe96(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1040 <syslog@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [47 x i8] c"failed to change directory to %s, code %d (%s)\00"
@errno = global i32 0
define i32 @set_run_directory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @chdir(i8* %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @LOG_ERR
%9 = load i8*, i8** %3
%10 = load i32, i32* @errno
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 @syslog(i32 %8, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10, i32 %12)
store i32 0, i32* %2
br label %15
14: ; preds = %1
store i32 1, i32* %2
br label %15
15: ; preds = %14, %7
%16 = load i32, i32* %2
ret i32 %16
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [47 x i8] c"failed to change directory to %s, code %d (%s)\00"
@errno = global i32 0
define i32 @set_run_directory(i8* %0) {
%2 = tail call i64 @chdir(i8* %0)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = load i32, i32* @LOG_ERR
%6 = load i32, i32* @errno
%7 = tail call i32 @strerror(i32 %6)
%8 = tail call i32 @syslog(i32 %5, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %6, i32 %7)
br label %9
9: ; preds = %1, %4
%10 = phi i32 [ 0, %4 ], [ 1, %1 ]
ret i32 %10
}