#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*/ close(int);
scalar_t__ fchdir(int);
int smm_errno_update(int);
int smm_cwd_pop(void *cwid) {
  union {
    void *u_poi;
    int u_int;
  } fd;
  fd.u_poi = cwid;
  if (fd.u_int <= 0) {
    return smm_errno_update(0);
  }
  if (fchdir(fd.u_int) < 0) {
    close(fd.u_int);
    return smm_errno_update((0xC0000000 | (4)));
  }
  close(fd.u_int);
  return smm_errno_update(0);
}


x86 assembly (clang, -O0):
<smm_cwd_pop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     115d <smm_cwd_pop+0x2d>
xor    %edi,%edi
call   1040 <smm_errno_update@plt>
mov    %eax,-0x4(%rbp)
jmp    119b <smm_cwd_pop+0x6b>
mov    -0x18(%rbp),%edi
call   1050 <fchdir@plt>
cmp    $0x0,%rax
jge    1189 <smm_cwd_pop+0x59>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    $0xc0000004,%edi
call   1040 <smm_errno_update@plt>
mov    %eax,-0x4(%rbp)
jmp    119b <smm_cwd_pop+0x6b>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
xor    %edi,%edi
call   1040 <smm_errno_update@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smm_cwd_pop>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %r14d,%r14d
jle    115b <smm_cwd_pop+0x2b>
mov    %r14d,%edi
call   1050 <fchdir@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1030 <close@plt>
sar    $0x3f,%rbx
and    $0xc0000004,%ebx
jmp    115d <smm_cwd_pop+0x2d>
xor    %ebx,%ebx
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <smm_errno_update@plt>

LLVM IR (-O0):
%union.anon = type { i8* }
define i32 @smm_cwd_pop(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %union.anon
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = bitcast %union.anon* %4 to i8**
store i8* %5, i8** %6
%7 = bitcast %union.anon* %4 to i32*
%8 = load i32, i32* %7
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @smm_errno_update(i32 0)
store i32 %11, i32* %2
br label %27
12: ; preds = %1
%13 = bitcast %union.anon* %4 to i32*
%14 = load i32, i32* %13
%15 = call i64 @fchdir(i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = bitcast %union.anon* %4 to i32*
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = call i32 @smm_errno_update(i32 -1073741820)
store i32 %21, i32* %2
br label %27
22: ; preds = %12
%23 = bitcast %union.anon* %4 to i32*
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = call i32 @smm_errno_update(i32 0)
store i32 %26, i32* %2
br label %27
27: ; preds = %22, %17, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @smm_cwd_pop(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = icmp slt i32 %3, 1
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i64 @fchdir(i32 %3)
%7 = icmp slt i64 %6, 0
%8 = tail call i32 @close(i32 %3)
%9 = select i1 %7, i32 -1073741820, i32 0
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ 0, %1 ], [ %9, %5 ]
%12 = tail call i32 @smm_errno_update(i32 %11)
ret i32 %12
}