#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ S_IRWXU;
int close(int);
int errno;
int mkdir(char *, int /*<<< orphan*/);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int, int);
int rmdir(char *);
int unlink(char *);
int test_basic(void) {
  int rc, fd;
  char *tmpdir = "basic-test.dir";
  char *tmpfile = "basic-test.file";
  rc = mkdir(tmpdir, S_IRWXU);
  if (rc) {
    printf("Fail to create directory %s, errno = %d at line %d!\n", tmpdir,
           errno, 71);
    return (1);
  }
  rc = rmdir(tmpdir);
  if (rc) {
    printf("Fail to remove directory %s, errno = %d at line %d!\n", tmpdir,
           errno, 76);
    return (1);
  }
  fd = open(tmpfile, O_CREAT | O_RDWR, S_IRWXU);
  if (fd < 0) {
    printf("Fail to create file %s, errno = %d at line %d!\n", tmpfile, errno,
           81);
    return (1);
  }
  rc = close(fd);
  if (rc < 0) {
    printf("Fail to close file %s, errno = %d at line %d!\n", tmpfile, errno,
           86);
    return (1);
  }
  rc = unlink(tmpfile);
  if (rc) {
    printf("Fail to remove file %s, errno = %d at line %d!\n", tmpfile, errno,
           91);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<test_basic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11c7 <test_basic+0x67>
mov    -0x18(%rbp),%rsi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
lea    0xe6e(%rip),%rdi
mov    $0x47,%ecx
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <test_basic+0x188>
mov    -0x18(%rbp),%rdi
call   1050 <rmdir@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1207 <test_basic+0xa7>
mov    -0x18(%rbp),%rsi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
lea    0xe63(%rip),%rdi
mov    $0x4c,%ecx
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <test_basic+0x188>
mov    -0x20(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    0x2dbd(%rip),%rax
or     (%rax),%esi
mov    0x2dbc(%rip),%rax
mov    (%rax),%edx
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1262 <test_basic+0x102>
mov    -0x20(%rbp),%rsi
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
lea    0xe3d(%rip),%rdi
mov    $0x51,%ecx
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <test_basic+0x188>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12a1 <test_basic+0x141>
mov    -0x20(%rbp),%rsi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
lea    0xe2e(%rip),%rdi
mov    $0x56,%ecx
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <test_basic+0x188>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12e1 <test_basic+0x181>
mov    -0x20(%rbp),%rsi
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
lea    0xe1d(%rip),%rdi
mov    $0x5b,%ecx
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <test_basic+0x188>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_basic>:
push   %rbx
mov    0x2e78(%rip),%rbx
mov    (%rbx),%esi
lea    0xe8f(%rip),%rdi
call   1040 <mkdir@plt>
test   %eax,%eax
je     1198 <test_basic+0x38>
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
lea    0xe95(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x47,%ecx
jmp    11c4 <test_basic+0x64>
lea    0xe61(%rip),%rdi
call   1050 <rmdir@plt>
test   %eax,%eax
je     11d0 <test_basic+0x70>
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
lea    0xe9c(%rip),%rdi
lea    0xe41(%rip),%rsi
mov    $0x4c,%ecx
call   1060 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x2e21(%rip),%rax
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    (%rbx),%edx
lea    0xe24(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     122d <test_basic+0xcd>
mov    %eax,%edi
call   1070 <close@plt>
test   %eax,%eax
js     124e <test_basic+0xee>
lea    0xe09(%rip),%rdi
call   1030 <unlink@plt>
test   %eax,%eax
je     126f <test_basic+0x10f>
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
lea    0xec9(%rip),%rdi
lea    0xde9(%rip),%rsi
mov    $0x5b,%ecx
jmp    11c4 <test_basic+0x64>
mov    0x2d94(%rip),%rax
mov    (%rax),%edx
lea    0xe4c(%rip),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x51,%ecx
jmp    11c4 <test_basic+0x64>
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
lea    0xe5b(%rip),%rdi
lea    0xdaa(%rip),%rsi
mov    $0x56,%ecx
jmp    11c4 <test_basic+0x64>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"basic-test.dir\00"
@.str.1 = [16 x i8] c"basic-test.file\00"
@S_IRWXU = global i32 0
@.str.2 = [53 x i8] c"Fail to create directory %s, errno = %d at line %d!\0A\00"
@errno = global i32 0
@.str.3 = [53 x i8] c"Fail to remove directory %s, errno = %d at line %d!\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.4 = [48 x i8] c"Fail to create file %s, errno = %d at line %d!\0A\00"
@.str.5 = [47 x i8] c"Fail to close file %s, errno = %d at line %d!\0A\00"
@.str.6 = [48 x i8] c"Fail to remove file %s, errno = %d at line %d!\0A\00"
define i32 @test_basic() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %4
%7 = load i32, i32* @S_IRWXU
%8 = call i32 @mkdir(i8* %6, i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i8*, i8** %4
%13 = load i32, i32* @errno
%14 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %13, i32 71)
store i32 1, i32* %1
br label %56
15: ; preds = %0
%16 = load i8*, i8** %4
%17 = call i32 @rmdir(i8* %16)
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i32, i32* @errno
%23 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* %21, i32 %22, i32 76)
store i32 1, i32* %1
br label %56
24: ; preds = %15
%25 = load i8*, i8** %5
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_RDWR
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IRWXU
%30 = call i32 @open(i8* %25, i32 %28, i32 %29)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i8*, i8** %5
%35 = load i32, i32* @errno
%36 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 %35, i32 81)
store i32 1, i32* %1
br label %56
37: ; preds = %24
%38 = load i32, i32* %3
%39 = call i32 @close(i32 %38)
store i32 %39, i32* %2
%40 = load i32, i32* %2
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i8*, i8** %5
%44 = load i32, i32* @errno
%45 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %43, i32 %44, i32 86)
store i32 1, i32* %1
br label %56
46: ; preds = %37
%47 = load i8*, i8** %5
%48 = call i32 @unlink(i8* %47)
store i32 %48, i32* %2
%49 = load i32, i32* %2
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i8*, i8** %5
%53 = load i32, i32* @errno
%54 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i8* %52, i32 %53, i32 91)
store i32 1, i32* %1
br label %56
55: ; preds = %46
store i32 0, i32* %1
br label %56
56: ; preds = %55, %51, %42, %33, %20, %11
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [15 x i8] c"basic-test.dir\00"
@.str.1 = [16 x i8] c"basic-test.file\00"
@S_IRWXU = global i32 0
@.str.2 = [53 x i8] c"Fail to create directory %s, errno = %d at line %d!\0A\00"
@errno = global i32 0
@.str.3 = [53 x i8] c"Fail to remove directory %s, errno = %d at line %d!\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.4 = [48 x i8] c"Fail to create file %s, errno = %d at line %d!\0A\00"
@.str.5 = [47 x i8] c"Fail to close file %s, errno = %d at line %d!\0A\00"
@.str.6 = [48 x i8] c"Fail to remove file %s, errno = %d at line %d!\0A\00"
define i32 @test_basic() {
%1 = load i32, i32* @S_IRWXU
%2 = tail call i32 @mkdir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = load i32, i32* @errno
%6 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5, i32 71)
br label %35
7: ; preds = %0
%8 = tail call i32 @rmdir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11, i32 76)
br label %35
13: ; preds = %7
%14 = load i32, i32* @O_CREAT
%15 = load i32, i32* @O_RDWR
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IRWXU
%18 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* @errno
%22 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 81)
br label %35
23: ; preds = %13
%24 = tail call i32 @close(i32 %18)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 86)
br label %35
29: ; preds = %23
%30 = tail call i32 @unlink(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 91)
br label %35
35: ; preds = %29, %32, %26, %20, %10, %4
%36 = phi i32 [ 1, %4 ], [ 1, %10 ], [ 1, %20 ], [ 1, %26 ], [ 1, %32 ], [ 0, %29 ]
ret i32 %36
}