#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*/ chdir(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void work_place(char *str) {
  char *temp;
  char *q;
  puts(str);
  temp = (char *)malloc(sizeof(char) * (strlen(str) + 1));
  strcpy(temp, str);
  q = temp + strlen(str);
  while (*q != '/')
    q--;
  *q = '\0';
  chdir(temp);
}


x86 assembly (clang, -O0):
<work_place>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11d1 <work_place+0x81>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11b0 <work_place+0x60>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <chdir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work_place>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
add    %r14,%rax
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,-0x1(%rax)
lea    -0x1(%rax),%rax
jne    1190 <work_place+0x40>
movb   $0x0,(%rax)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <chdir@plt>

LLVM IR (-O0):
define void @work_place(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @puts(i8* %5)
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8* %22, i8** %4
br label %23
23: ; preds = %28, %1
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 47
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %4
br label %23
31: ; preds = %23
%32 = load i8*, i8** %4
store i8 0, i8* %32
%33 = load i8*, i8** %3
%34 = call i32 @chdir(i8* %33)
ret void
}

LLVM IR (-O2):
define void @work_place(i8* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strcpy(i8* %6, i8* %0)
%8 = tail call i32 @strlen(i8* %0)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
br label %11
11: ; preds = %11, %1
%12 = phi i8* [ %10, %1 ], [ %15, %11 ]
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
%15 = getelementptr inbounds i8, i8* %12, i64 -1
br i1 %14, label %16, label %11
16: ; preds = %11
store i8 0, i8* %12
%17 = tail call i32 @chdir(i8* %6)
ret void
}