#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 st_mode;
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int main(int argc, char **argv) {
  struct stat statres;
  int ret;
  printf("%s\n", argv[1]);
  ret = stat(argv[1], &statres);
  if (ret != 0) {
    perror("stat()");
    return -1;
  }
  printf("0%o %d %s\n", statres.st_mode & 0777, statres.st_size, argv[1]);
  if (statres.st_mode & (1 << 8)) {
    printf("r");
  } else {
    printf("-");
  }
  if (statres.st_mode & (1 << 7)) {
    printf("w");
  } else {
    printf("-");
  }
  if (statres.st_mode & (1 << 6)) {
    printf("x\n");
  } else {
    printf("-\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1192 <main+0x62>
lea    0xe7f(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124f <main+0x11f>
mov    -0x18(%rbp),%esi
and    $0x1ff,%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0x100,%eax
cmp    $0x0,%eax
je     11d8 <main+0xa8>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e6 <main+0xb6>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     120a <main+0xda>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1218 <main+0xe8>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     123a <main+0x10a>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1248 <main+0x118>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %eax,%eax
jne    11eb <main+0x9b>
mov    0x8(%rsp),%ebp
mov    0xc(%rsp),%edx
mov    %ebp,%esi
and    $0x1ff,%esi
mov    0x8(%rbx),%rcx
lea    0xe76(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x100,%ebp
mov    $0x2d,%ebx
mov    $0x72,%edi
cmove  %ebx,%edi
call   1030 <putchar@plt>
test   $0x80,%bpl
mov    $0x77,%edi
cmove  %ebx,%edi
call   1030 <putchar@plt>
test   $0x40,%bpl
jne    11d3 <main+0x83>
lea    0xe41(%rip),%rdi
jmp    11da <main+0x8a>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r14d
jmp    11df <main+0x8f>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [7 x i8] c"stat()\00"
@.str.2 = [11 x i8] c"0%o %d %s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"-\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"x\0A\00"
@.str.7 = [3 x i8] c"-\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @stat(i8* %14, %struct.stat* %6)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %57
20: ; preds = %2
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, 511
%24 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %25, i8* %28)
%30 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, 256
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
36: ; preds = %20
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
%39 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = and i32 %40, 128
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %47
45: ; preds = %38
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
%48 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%49 = load i32, i32* %48
%50 = and i32 %49, 64
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %56
54: ; preds = %47
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
store i32 0, i32* %3
br label %57
57: ; preds = %56, %18
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@.str.1 = [7 x i8] c"stat()\00"
@.str.2 = [11 x i8] c"0%o %d %s\0A\00"
@str = [2 x i8] c"-\00"
@str.8 = [2 x i8] c"x\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
%8 = load i8*, i8** %5
%9 = call i32 @stat(i8* %8, %struct.stat* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %35
13: ; preds = %2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, 511
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%18 = load i32, i32* %17
%19 = load i8*, i8** %5
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %18, i8* %19)
%21 = and i32 %15, 256
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i32 45, i32 114
%24 = tail call i32 @putchar(i32 %23)
%25 = and i32 %15, 128
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 45, i32 119
%28 = tail call i32 @putchar(i32 %27)
%29 = and i32 %15, 64
%30 = icmp eq i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %13
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
br label %35
33: ; preds = %13
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %31, %33, %11
%36 = phi i32 [ -1, %11 ], [ 0, %33 ], [ 0, %31 ]
ret i32 %36
}