#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 chdir(char *);
int /*<<< orphan*/ printf(char *);
char *strtok(char *, char *);
int do_cd(char *comando) {
  char *caminho;
  int cod_retorno;
  strtok(comando, " ");
  caminho = strtok(NULL, " ");
  cod_retorno = chdir(caminho);
  if (cod_retorno == -1) {
    printf("Ops, diretorio nao encontrado.\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<do_cd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strtok@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xea9(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <chdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    118e <do_cd+0x5e>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1195 <do_cd+0x65>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_cd>:
push   %rbx
lea    0xec8(%rip),%rbx
mov    %rbx,%rsi
call   1050 <strtok@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <strtok@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     1160 <do_cd+0x30>
pop    %rbx
ret
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [32 x i8] c"Ops, diretorio nao encontrado.\0A\00"
define i32 @do_cd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @chdir(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %16
15: ; preds = %1
store i32 1, i32* %2
br label %16
16: ; preds = %15, %13
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@str = [31 x i8] c"Ops, diretorio nao encontrado.\00"
define i32 @do_cd(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @chdir(i8* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %1, %6
%9 = phi i32 [ 0, %6 ], [ 1, %1 ]
ret i32 %9
}