#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 {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
  scalar_t__ st_ctime;
  scalar_t__ st_mtime;
  scalar_t__ st_atime;
  scalar_t__ st_blocks;
  scalar_t__ st_blksize;
  scalar_t__ st_size;
  scalar_t__ st_rdev;
  scalar_t__ st_gid;
  scalar_t__ st_uid;
  scalar_t__ st_nlink;
  scalar_t__ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fstat(int, struct stat *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ printf(char *, char const *, unsigned long, unsigned long,
                          unsigned long, unsigned long, unsigned long,
                          unsigned long, unsigned long, unsigned long long,
                          unsigned long, unsigned long, unsigned long,
                          unsigned long, unsigned long);
int stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
void do_stats(const char *path) {
  int fd;
  int err;
  struct stat stbuf1, stbuf2;
  fd = open(path, O_RDONLY);
  if (fd < 0) {
    perror(path);
    return;
  }
  err = fstat(fd, &stbuf1);
  if (!err)
    err = stat(path, &stbuf2);
  if (err) {
    perror(path);
    goto out;
  }
  if (stbuf1.st_dev != stbuf2.st_dev || stbuf1.st_ino != stbuf2.st_ino) {
    (void)fprintf(stderr, "%s: [f]stat info mismatch\n", path);
    goto out;
  }
  printf("%s:"
         " dev %lu,"
         " ino %lu,"
         " mode %lu,"
         " nlink %lu,"
         " uid %lu,"
         " gid %lu,"
         " rdev %lu,"
         " size %llu,"
         " blksize %lu,"
         " blocks %lu,"
         " atime %lu,"
         " mtime %lu,"
         " ctime %lu"
         "\n",
         path, (unsigned long)stbuf1.st_dev, (unsigned long)stbuf1.st_ino,
         (unsigned long)stbuf1.st_mode, (unsigned long)stbuf1.st_nlink,
         (unsigned long)stbuf1.st_uid, (unsigned long)stbuf1.st_gid,
         (unsigned long)stbuf1.st_rdev, (unsigned long long)stbuf1.st_size,
         (unsigned long)stbuf1.st_blksize, (unsigned long)stbuf1.st_blocks,
         (unsigned long)stbuf1.st_atime, (unsigned long)stbuf1.st_mtime,
         (unsigned long)stbuf1.st_ctime);
out:
  if (close(fd) != 0)
    perror("closing file");
}


x86 assembly (clang, -O0):
<do_stats>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rdi,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11b5 <do_stats+0x45>
mov    -0x30(%rbp),%rdi
call   1080 <perror@plt>
jmp    12ea <do_stats+0x17a>
mov    -0x34(%rbp),%edi
lea    -0xa0(%rbp),%rsi
call   1090 <fstat@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    11e4 <do_stats+0x74>
mov    -0x30(%rbp),%rdi
lea    -0x108(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     11fc <do_stats+0x8c>
mov    -0x30(%rbp),%rdi
call   1080 <perror@plt>
jmp    12cc <do_stats+0x15c>
mov    -0xa0(%rbp),%rax
cmp    -0x108(%rbp),%rax
jne    1224 <do_stats+0xb4>
mov    -0x98(%rbp),%rax
cmp    -0x100(%rbp),%rax
je     1242 <do_stats+0xd2>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdc8(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12cc <do_stats+0x15c>
mov    -0x30(%rbp),%rsi
mov    -0xa0(%rbp),%rdx
mov    -0x98(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%r13
mov    -0x60(%rbp),%r12
mov    -0x68(%rbp),%r15
mov    -0x70(%rbp),%r14
mov    -0x78(%rbp),%rbx
mov    -0x80(%rbp),%r11
mov    -0x88(%rbp),%r10
mov    -0x90(%rbp),%rdi
mov    %rdi,-0x110(%rbp)
lea    0xd87(%rip),%rdi
mov    %rax,(%rsp)
mov    -0x110(%rbp),%rax
mov    %r13,0x8(%rsp)
mov    %r12,0x10(%rsp)
mov    %r15,0x18(%rsp)
mov    %r14,0x20(%rsp)
mov    %rbx,0x28(%rsp)
mov    %r11,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
call   1030 <printf@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     12ea <do_stats+0x17a>
lea    0xdc2(%rip),%rdi
call   1080 <perror@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_stats>:
push   %rbp
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,%rbx
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1264 <do_stats+0xf4>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1090 <fstat@plt>
test   %eax,%eax
jne    1253 <do_stats+0xe3>
lea    0x70(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %eax,%eax
jne    1253 <do_stats+0xe3>
mov    0x8(%rsp),%rdx
cmp    0x70(%rsp),%rdx
jne    1225 <do_stats+0xb5>
mov    0x10(%rsp),%rcx
cmp    0x78(%rsp),%rcx
jne    1225 <do_stats+0xb5>
mov    0x68(%rsp),%r8
mov    0x60(%rsp),%r9
sub    $0x8,%rsp
lea    0xe31(%rip),%rdi
mov    %rbx,%rsi
push   0x20(%rsp)
push   0x30(%rsp)
push   0x40(%rsp)
push   0x50(%rsp)
push   0x60(%rsp)
push   0x70(%rsp)
push   0x80(%rsp)
push   0x90(%rsp)
push   0xa0(%rsp)
call   1030 <printf@plt>
add    $0x50,%rsp
jmp    123d <do_stats+0xcd>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
test   %rax,%rax
jne    125d <do_stats+0xed>
add    $0xd8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
call   1080 <perror@plt>
jmp    123d <do_stats+0xcd>
lea    0xe43(%rip),%rbx
mov    %rbx,%rdi
add    $0xd8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
%struct.stat = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"%s: [f]stat info mismatch\0A\00"
@.str.1 = [140 x i8] c"%s: dev %lu, ino %lu, mode %lu, nlink %lu, uid %lu, gid %lu, rdev %lu, size %llu, blksize %lu, blocks %lu, atime %lu, mtime %lu, ctime %lu\0A\00"
@.str.2 = [13 x i8] c"closing file\00"
define void @do_stats(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = alloca %struct.stat
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @perror(i8* %13)
br label %80
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 @fstat(i32 %16, %struct.stat* %5)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = call i32 @stat(i8* %21, %struct.stat* %6)
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %15
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %2
%28 = call i32 @perror(i8* %27)
br label %74
29: ; preds = %23
%30 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%33 = load i64, i64* %32
%34 = icmp ne i64 %31, %33
br i1 %34, label %41, label %35
35: ; preds = %29
%36 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%37 = load i64, i64* %36
%38 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%39 = load i64, i64* %38
%40 = icmp ne i64 %37, %39
br i1 %40, label %41, label %45
41: ; preds = %35, %29
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %2
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %43)
br label %74
45: ; preds = %35
%46 = load i8*, i8** %2
%47 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 1
%50 = load i64, i64* %49
%51 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 12
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 11
%54 = load i64, i64* %53
%55 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 10
%56 = load i64, i64* %55
%57 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 9
%58 = load i64, i64* %57
%59 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 8
%60 = load i64, i64* %59
%61 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 7
%62 = load i64, i64* %61
%63 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 6
%64 = load i64, i64* %63
%65 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 5
%66 = load i64, i64* %65
%67 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 4
%68 = load i64, i64* %67
%69 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 3
%70 = load i64, i64* %69
%71 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 2
%72 = load i64, i64* %71
%73 = call i32 @printf(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i8* %46, i64 %48, i64 %50, i64 %52, i64 %54, i64 %56, i64 %58, i64 %60, i64 %62, i64 %64, i64 %66, i64 %68, i64 %70, i64 %72)
br label %74
74: ; preds = %45, %41, %26
%75 = load i32, i32* %3
%76 = call i64 @close(i32 %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %74
%79 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %80
80: ; preds = %12, %78, %74
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [27 x i8] c"%s: [f]stat info mismatch\0A\00"
@.str.1 = [140 x i8] c"%s: dev %lu, ino %lu, mode %lu, nlink %lu, uid %lu, gid %lu, rdev %lu, size %llu, blksize %lu, blocks %lu, atime %lu, mtime %lu, ctime %lu\0A\00"
@.str.2 = [13 x i8] c"closing file\00"
define void @do_stats(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %2 to i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %59, label %9
9: ; preds = %1
%10 = call i32 @fstat(i32 %7, %struct.stat* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @stat(i8* %0, %struct.stat* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %9, %12
%16 = tail call i32 @perror(i8* %0)
br label %56
17: ; preds = %12
%18 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%21 = load i64, i64* %20
%22 = icmp eq i64 %19, %21
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%27 = load i64, i64* %26
%28 = icmp eq i64 %25, %27
br i1 %28, label %32, label %29
29: ; preds = %23, %17
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %56
32: ; preds = %23
%33 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 12
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 11
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 10
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 9
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 8
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 7
%44 = load i64, i64* %43
%45 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 6
%46 = load i64, i64* %45
%47 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 5
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 4
%50 = load i64, i64* %49
%51 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 3
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 2
%54 = load i64, i64* %53
%55 = tail call i32 @printf(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %19, i64 %25, i64 %34, i64 %36, i64 %38, i64 %40, i64 %42, i64 %44, i64 %46, i64 %48, i64 %50, i64 %52, i64 %54)
br label %56
56: ; preds = %32, %29, %15
%57 = tail call i64 @close(i32 %7)
%58 = icmp eq i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %56, %1
%60 = phi i8* [ %0, %1 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %56 ]
%61 = tail call i32 @perror(i8* %60)
br label %62
62: ; preds = %59, %56
ret void
}