#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 int /*<<< orphan*/ DIR;

/* Variables and functions */
int chdir(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int init2(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int init1(void) {
  int r = 0;
  DIR *dir = NULL;
  if (chdir("servers") == -1)
    return 0;
  if (!(dir = opendir(".")))
    return 0;
  r = init2(dir);
  closedir(dir);
  return r;
}


x86 assembly (clang, -O0):
<init1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xea2(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1178 <init1+0x38>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <init1+0x79>
lea    0xe89(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119e <init1+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <init1+0x79>
mov    -0x10(%rbp),%rdi
call   1060 <init2@plt>
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init1>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     117e <init1+0x3e>
lea    0xead(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     117e <init1+0x3e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <init2@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %ebp,%eax
jmp    1180 <init1+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"servers\00"
@.str.1 = [2 x i8] c".\00"
define i32 @init1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %2
store i32* null, i32** %3
%4 = call i32 @chdir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %17
7: ; preds = %0
%8 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %7
store i32 0, i32* %1
br label %17
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = call i32 @init2(i32* %12)
store i32 %13, i32* %2
%14 = load i32*, i32** %3
%15 = call i32 @closedir(i32* %14)
%16 = load i32, i32* %2
store i32 %16, i32* %1
br label %17
17: ; preds = %11, %10, %6
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [8 x i8] c"servers\00"
@.str.1 = [2 x i8] c".\00"
define i32 @init1() {
%1 = tail call i32 @chdir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, -1
br i1 %2, label %9, label %3
3: ; preds = %0
%4 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @init2(i32* %4)
%8 = tail call i32 @closedir(i32* %4)
br label %9
9: ; preds = %3, %0, %6
%10 = phi i32 [ %7, %6 ], [ 0, %0 ], [ 0, %3 ]
ret i32 %10
}