#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 cg_get_path(char const *, char const *, int /*<<< orphan*/ *, char **);
int errno;
int /*<<< orphan*/ free(char *);
int rmdir(char *);
int cg_rmdir(const char *controller, const char *path) {
  char *p;
  int r;
  if ((r = cg_get_path(controller, path, NULL, &p)) < 0)
    return r;
  r = rmdir(p);
  free(p);
  return r < 0 ? -errno : 0;
}


x86 assembly (clang, -O0):
<cg_rmdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
call   1050 <cg_get_path@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    116c <cg_rmdir+0x3c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <cg_rmdir+0x7e>
mov    -0x20(%rbp),%rdi
call   1040 <rmdir@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
jge    119e <cg_rmdir+0x6e>
xor    %eax,%eax
mov    0x2e4c(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x28(%rbp)
jmp    11a8 <cg_rmdir+0x78>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    11a8 <cg_rmdir+0x78>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_rmdir>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    %rsp,%rcx
xor    %edx,%edx
call   1050 <cg_get_path@plt>
test   %eax,%eax
js     116b <cg_rmdir+0x3b>
mov    (%rsp),%rdi
call   1040 <rmdir@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x2e80(%rip),%rax
sub    (%rax),%r14d
sar    $0x1f,%ebx
and    %r14d,%ebx
jmp    116d <cg_rmdir+0x3d>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @cg_rmdir(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32 @cg_get_path(i8* %8, i8* %9, i32* null, i8** %6)
store i32 %10, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* %7
store i32 %13, i32* %3
br label %27
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @rmdir(i8* %15)
store i32 %16, i32* %7
%17 = load i8*, i8** %6
%18 = call i32 @free(i8* %17)
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* @errno
%23 = sub nsw i32 0, %22
br label %25
24: ; preds = %14
br label %25
25: ; preds = %24, %21
%26 = phi i32 [ %23, %21 ], [ 0, %24 ]
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @cg_rmdir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @cg_get_path(i8* %0, i8* %1, i32* null, i8** %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i32 @rmdir(i8* %8)
%10 = load i8*, i8** %3
%11 = call i32 @free(i8* %10)
%12 = icmp slt i32 %9, 0
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
%15 = select i1 %12, i32 %14, i32 0
br label %16
16: ; preds = %2, %7
%17 = phi i32 [ %15, %7 ], [ %5, %2 ]
ret i32 %17
}