#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 creat(char *, int);
int mkdir(char *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int a;
  a = chdir("/home/shahas/Desktop/");
  if (a == 0)
    printf("Directory changed successfully\n");
  a = mkdir("new_dir1", 0777);
  if (a == 0)
    printf("New Directory created successfully\n");
  a = chdir("new_dir1");
  if (a == 0)
    printf("Directory changed successfully\n");
  a = creat("file.txt", 0777);
  if (a >= 0)
    printf("file.txt created successfully\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1174 <main+0x34>
lea    0xea7(%rip),%rdi
call   1050 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    119e <main+0x5e>
lea    0xea6(%rip),%rdi
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11c3 <main+0x83>
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x1ff,%esi
call   1060 <creat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11ed <main+0xad>
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
call   1050 <chdir@plt>
test   %eax,%eax
jne    115d <main+0x1d>
lea    0xf11(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb2(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
jne    117e <main+0x3e>
lea    0xecd(%rip),%rdi
call   1040 <puts@plt>
lea    0xe91(%rip),%rdi
call   1050 <chdir@plt>
test   %eax,%eax
jne    119a <main+0x5a>
lea    0xed4(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7e(%rip),%rdi
mov    $0x1ff,%esi
call   1060 <creat@plt>
test   %eax,%eax
js     11bb <main+0x7b>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"/home/shahas/Desktop/\00"
@.str.1 = [32 x i8] c"Directory changed successfully\0A\00"
@.str.2 = [9 x i8] c"new_dir1\00"
@.str.3 = [36 x i8] c"New Directory created successfully\0A\00"
@.str.4 = [9 x i8] c"file.txt\00"
@.str.5 = [31 x i8] c"file.txt created successfully\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @chdir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 511)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i32 @chdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = call i32 @creat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 511)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"/home/shahas/Desktop/\00"
@.str.2 = [9 x i8] c"new_dir1\00"
@.str.4 = [9 x i8] c"file.txt\00"
@str = [30 x i8] c"file.txt created successfully\00"
@str.7 = [35 x i8] c"New Directory created successfully\00"
@str.8 = [31 x i8] c"Directory changed successfully\00"
define i32 @main() {
%1 = tail call i32 @chdir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 511)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.7, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @chdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @creat(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 511)
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
ret i32 0
}