#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 */
scalar_t__ ENXIO;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ chdir(char *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int main() {
  if (chdir("/") < 0 && errno == ENXIO)
    exit(EXIT_SUCCESS);
  fprintf(stderr, "got errno=%m\n");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
jge    117d <main+0x4d>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
jne    117d <main+0x4d>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
call   1030 <chdir@plt>
test   %rax,%rax
jns    1166 <main+0x36>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1166 <main+0x36>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@ENXIO = global i64 0
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"got errno=%m\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %0
%5 = load i64, i64* @errno
%6 = load i64, i64* @ENXIO
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @EXIT_SUCCESS
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %4, %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@ENXIO = global i64 0
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"got errno=%m\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = load i64, i64* @errno
%5 = load i64, i64* @ENXIO
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @EXIT_SUCCESS
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3, %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
}