#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gend();
int /*<<< orphan*/ ggetch();
int /*<<< orphan*/ ginit();
int /*<<< orphan*/ gmove(int, int);
int /*<<< orphan*/ gprintf(char *, char *);
int /*<<< orphan*/ reader(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct stat st_buf;
  char *gamedir, *p;
  if (argc > 1) {
    gamedir = argv[1];
    if (chdir(gamedir) == -1) {
      gmove(20, 18);
      gprintf("Error Setting Directory %s\n", gamedir);
      ggetch();
      gend();
      exit(1);
    }
  }
  ginit();
  reader("news", 0);
  gend();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11fa <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11f5 <main+0x75>
mov    $0x14,%edi
mov    $0x12,%esi
call   1080 <gmove@plt>
mov    -0x20(%rbp),%rsi
lea    0xe28(%rip),%rdi
call   1040 <gprintf@plt>
mov    $0x0,%al
call   1050 <ggetch@plt>
mov    $0x0,%al
call   10a0 <gend@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11fa <main+0x7a>
mov    $0x0,%al
call   1070 <ginit@plt>
lea    0xe14(%rip),%rdi
xor    %esi,%esi
call   1030 <reader@plt>
mov    $0x0,%al
call   10a0 <gend@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jl     11cd <main+0x4d>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11cd <main+0x4d>
mov    $0x14,%edi
mov    $0x12,%esi
call   1080 <gmove@plt>
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
call   1040 <gprintf@plt>
xor    %eax,%eax
call   1050 <ggetch@plt>
xor    %eax,%eax
call   10a0 <gend@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1070 <ginit@plt>
lea    0xe41(%rip),%rdi
xor    %esi,%esi
call   1030 <reader@plt>
xor    %eax,%eax
call   10a0 <gend@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [28 x i8] c"Error Setting Directory %s\0A\00"
@.str.1 = [5 x i8] c"news\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %26
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = call i32 @chdir(i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %25
18: ; preds = %11
%19 = call i32 @gmove(i32 20, i32 18)
%20 = load i8*, i8** %7
%21 = call i32 @gprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 (...) @ggetch()
%23 = call i32 (...) @gend()
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %11
br label %26
26: ; preds = %25, %2
%27 = call i32 (...) @ginit()
%28 = call i32 @reader(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0)
%29 = call i32 (...) @gend()
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [28 x i8] c"Error Setting Directory %s\0A\00"
@.str.1 = [5 x i8] c"news\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @chdir(i8* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = tail call i32 @gmove(i32 20, i32 18)
%11 = tail call i32 @gprintf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %6)
%12 = tail call i32 (...) @ggetch()
%13 = tail call i32 (...) @gend()
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4, %2
%16 = tail call i32 (...) @ginit()
%17 = tail call i32 @reader(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0)
%18 = tail call i32 (...) @gend()
%19 = tail call i32 @exit(i32 0)
unreachable
}