#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*/ perror(char *);
int put_file(char *, char const *);
int /*<<< orphan*/ show_state();
int cmd_state(const char *newstate) {
  if (chdir("../../") == -1) {
    perror("../../");
    return 1;
  }
  if (newstate == NULL) {
    show_state();
  } else {
    return put_file("state", newstate);
  }
}


x86 assembly (clang, -O0):
<cmd_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1179 <cmd_state+0x39>
lea    0xe98(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <cmd_state+0x63>
cmpq   $0x0,-0x10(%rbp)
jne    1190 <cmd_state+0x50>
mov    $0x0,%al
call   1060 <show_state@plt>
jmp    11a3 <cmd_state+0x63>
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1040 <put_file@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_state>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
je     1178 <cmd_state+0x38>
test   %rbx,%rbx
je     116a <cmd_state+0x2a>
lea    0xea6(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1040 <put_file@plt>
xor    %eax,%eax
call   1060 <show_state@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe81(%rip),%rdi
call   1050 <perror@plt>
jmp    1171 <cmd_state+0x31>

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

LLVM IR (-O2):
@.str = [7 x i8] c"../../\00"
@.str.1 = [6 x i8] c"state\00"
define i32 @cmd_state(i8* %0) {
%2 = tail call i32 @chdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
6: ; preds = %1
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i32 (...) @show_state()
br label %12
10: ; preds = %6
%11 = tail call i32 @put_file(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %4, %10, %8
%13 = phi i32 [ 1, %4 ], [ undef, %8 ], [ %11, %10 ]
ret i32 %13
}