#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 /*<<< orphan*/ assert(int);
int file_exists(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ run_shell_command(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void test_file_exists() {
  char *test_filename = "/tmp/scalam_test_file_exists";
  char cmdstr[256];
  printf("test_file_exists...");
  sprintf(cmdstr, "touch %s", test_filename);
  run_shell_command(cmdstr);
  assert(file_exists(test_filename));
  sprintf(cmdstr, "rm %s", test_filename);
  run_shell_command(cmdstr);
  assert(!file_exists(test_filename));
  printf("Ok\n");
}


x86 assembly (clang, -O0):
<test_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe9e(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xeb0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xead(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <run_shell_command@plt>
mov    -0x8(%rbp),%rdi
call   1030 <file_exists@plt>
mov    %eax,%edi
call   1060 <assert@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe83(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <run_shell_command@plt>
mov    -0x8(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file_exists>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xeac(%rip),%rdi
call   1060 <printf@plt>
lea    0xeb4(%rip),%rsi
lea    0xe7c(%rip),%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <run_shell_command@plt>
mov    %r14,%rdi
call   1030 <file_exists@plt>
mov    %eax,%edi
call   1070 <assert@plt>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <run_shell_command@plt>
mov    %r14,%rdi
call   1030 <file_exists@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/tmp/scalam_test_file_exists\00"
@.str.1 = [20 x i8] c"test_file_exists...\00"
@.str.2 = [9 x i8] c"touch %s\00"
@.str.3 = [6 x i8] c"rm %s\00"
@.str.4 = [4 x i8] c"Ok\0A\00"
define void @test_file_exists() {
%1 = alloca i8*
%2 = alloca [256 x i8]
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8** %1
%3 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = call i32 @sprintf(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = call i32 @run_shell_command(i8* %7)
%9 = load i8*, i8** %1
%10 = call i32 @file_exists(i8* %9)
%11 = call i32 @assert(i32 %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = load i8*, i8** %1
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = call i32 @run_shell_command(i8* %15)
%17 = load i8*, i8** %1
%18 = call i32 @file_exists(i8* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"/tmp/scalam_test_file_exists\00"
@.str.1 = [20 x i8] c"test_file_exists...\00"
@.str.2 = [9 x i8] c"touch %s\00"
@.str.3 = [6 x i8] c"rm %s\00"
@str = [3 x i8] c"Ok\00"
define void @test_file_exists() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @run_shell_command(i8* %2)
%6 = call i32 @file_exists(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @assert(i32 %6)
%8 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @run_shell_command(i8* %2)
%10 = call i32 @file_exists(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret void
}