#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*/ free(char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ slog_csoup_format(char *, ...);
int /*<<< orphan*/ slog_csoup_puts(int /*<<< orphan*/, int, int /*<<< orphan*/);
int smm_chdir(char *);
char *smm_cwd_alloc(int /*<<< orphan*/);
int /*<<< orphan*/ smm_cwd_pop(char *);
char *smm_cwd_push();
int do_push_dir(char *path) {
  char *cwd, *cid;
  int rc;
  cwd = smm_cwd_alloc(0);
  slog_csoup_puts(0, (8 | 0), slog_csoup_format("Current: %s\n", cwd));
  free(cwd);
  cid = smm_cwd_push();
  rc = smm_chdir(path);
  cwd = smm_cwd_alloc(0);
  slog_csoup_puts(0, (8 | 0), slog_csoup_format("Enter: %s\n", cwd));
  free(cwd);
  smm_cwd_pop(cid);
  cwd = smm_cwd_alloc(0);
  slog_csoup_puts(0, (8 | 0), slog_csoup_format("Return: %s\n", cwd));
  free(cwd);
  slog_csoup_puts(0, (8 | 0),
                  slog_csoup_format("Press any key to continue ... "));
  getchar();
  slog_csoup_puts(0, (8 | 0), slog_csoup_format("(%d)\n", rc));
  return 0;
}


x86 assembly (clang, -O0):
<do_push_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
call   1070 <smm_cwd_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   10a0 <slog_csoup_format@plt>
mov    %eax,%edx
xor    %edi,%edi
mov    $0x8,%esi
call   1050 <slog_csoup_puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1090 <smm_cwd_push@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <smm_chdir@plt>
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1070 <smm_cwd_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   10a0 <slog_csoup_format@plt>
mov    %eax,%edx
xor    %edi,%edi
mov    $0x8,%esi
call   1050 <slog_csoup_puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1080 <smm_cwd_pop@plt>
xor    %edi,%edi
call   1070 <smm_cwd_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   10a0 <slog_csoup_format@plt>
mov    %eax,%edx
xor    %edi,%edi
mov    $0x8,%esi
call   1050 <slog_csoup_puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   10a0 <slog_csoup_format@plt>
mov    %eax,%edx
xor    %edi,%edi
mov    $0x8,%esi
call   1050 <slog_csoup_puts@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x1c(%rbp),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   10a0 <slog_csoup_format@plt>
mov    %eax,%edx
xor    %edi,%edi
mov    $0x8,%esi
call   1050 <slog_csoup_puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_push_dir>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %edi,%edi
call   1070 <smm_cwd_alloc@plt>
mov    %rax,%rbx
lea    0xe68(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <slog_csoup_format@plt>
xor    %edi,%edi
mov    $0x8,%esi
mov    %eax,%edx
call   1050 <slog_csoup_puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1090 <smm_cwd_push@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <smm_chdir@plt>
mov    %eax,%r14d
xor    %edi,%edi
call   1070 <smm_cwd_alloc@plt>
mov    %rax,%rbp
lea    0xe2f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <slog_csoup_format@plt>
xor    %edi,%edi
mov    $0x8,%esi
mov    %eax,%edx
call   1050 <slog_csoup_puts@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1080 <smm_cwd_pop@plt>
xor    %edi,%edi
call   1070 <smm_cwd_alloc@plt>
mov    %rax,%rbx
lea    0xe01(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <slog_csoup_format@plt>
xor    %edi,%edi
mov    $0x8,%esi
mov    %eax,%edx
call   1050 <slog_csoup_puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   10a0 <slog_csoup_format@plt>
xor    %edi,%edi
mov    $0x8,%esi
mov    %eax,%edx
call   1050 <slog_csoup_puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
lea    0xde2(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   10a0 <slog_csoup_format@plt>
xor    %edi,%edi
mov    $0x8,%esi
mov    %eax,%edx
call   1050 <slog_csoup_puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Current: %s\0A\00"
@.str.1 = [11 x i8] c"Enter: %s\0A\00"
@.str.2 = [12 x i8] c"Return: %s\0A\00"
@.str.3 = [31 x i8] c"Press any key to continue ... \00"
@.str.4 = [6 x i8] c"(%d)\0A\00"
define i32 @do_push_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i8* @smm_cwd_alloc(i32 0)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32 @slog_csoup_puts(i32 0, i32 8, i32 %8)
%10 = load i8*, i8** %3
%11 = call i32 @free(i8* %10)
%12 = call i8* (...) @smm_cwd_push()
store i8* %12, i8** %4
%13 = load i8*, i8** %2
%14 = call i32 @smm_chdir(i8* %13)
store i32 %14, i32* %5
%15 = call i8* @smm_cwd_alloc(i32 0)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @slog_csoup_puts(i32 0, i32 8, i32 %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %4
%22 = call i32 @smm_cwd_pop(i8* %21)
%23 = call i8* @smm_cwd_alloc(i32 0)
store i8* %23, i8** %3
%24 = load i8*, i8** %3
%25 = call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @slog_csoup_puts(i32 0, i32 8, i32 %25)
%27 = load i8*, i8** %3
%28 = call i32 @free(i8* %27)
%29 = call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @slog_csoup_puts(i32 0, i32 8, i32 %29)
%31 = call i32 (...) @getchar()
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = call i32 @slog_csoup_puts(i32 0, i32 8, i32 %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Current: %s\0A\00"
@.str.1 = [11 x i8] c"Enter: %s\0A\00"
@.str.2 = [12 x i8] c"Return: %s\0A\00"
@.str.3 = [31 x i8] c"Press any key to continue ... \00"
@.str.4 = [6 x i8] c"(%d)\0A\00"
define i32 @do_push_dir(i8* %0) {
%2 = tail call i8* @smm_cwd_alloc(i32 0)
%3 = tail call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = tail call i32 @slog_csoup_puts(i32 0, i32 8, i32 %3)
%5 = tail call i32 @free(i8* %2)
%6 = tail call i8* (...) @smm_cwd_push()
%7 = tail call i32 @smm_chdir(i8* %0)
%8 = tail call i8* @smm_cwd_alloc(i32 0)
%9 = tail call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = tail call i32 @slog_csoup_puts(i32 0, i32 8, i32 %9)
%11 = tail call i32 @free(i8* %8)
%12 = tail call i32 @smm_cwd_pop(i8* %6)
%13 = tail call i8* @smm_cwd_alloc(i32 0)
%14 = tail call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call i32 @slog_csoup_puts(i32 0, i32 8, i32 %14)
%16 = tail call i32 @free(i8* %13)
%17 = tail call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @slog_csoup_puts(i32 0, i32 8, i32 %17)
%19 = tail call i32 (...) @getchar()
%20 = tail call i32 (i8*, ...) @slog_csoup_format(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%21 = tail call i32 @slog_csoup_puts(i32 0, i32 8, i32 %20)
ret i32 0
}