#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;
};

/* Variables and functions */
int S_IRGRP;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int stat(char *, struct stat *);
int main(void) {
  struct stat buf;
  if (stat("./test.txt", &buf) == -1) {
    printf("stat error\n");
    exit(0);
  }
  if ((buf.st_mode & S_IRGRP) != 0)
    printf("user of the group can read\n");
  else
    printf("user of the group can not read\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    116b <main+0x3b>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
mov    0x2e6b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1191 <main+0x61>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
jmp    119d <main+0x6d>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xec8(%rip),%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     116c <main+0x3c>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xeb3(%rip),%rax
lea    0xecb(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [11 x i8] c"./test.txt\00"
@.str.1 = [12 x i8] c"stat error\0A\00"
@S_IRGRP = global i32 0
@.str.2 = [28 x i8] c"user of the group can read\0A\00"
@.str.3 = [32 x i8] c"user of the group can not read\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.stat
store i32 0, i32* %1
%3 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* @S_IRGRP
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %18
16: ; preds = %8
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [11 x i8] c"./test.txt\00"
@S_IRGRP = global i32 0
@str = [31 x i8] c"user of the group can not read\00"
@str.4 = [27 x i8] c"user of the group can read\00"
@str.5 = [11 x i8] c"stat error\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = load i32, i32* @S_IRGRP
%12 = and i32 %11, %10
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) %14)
ret i32 0
}