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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int fstat(int, struct stat *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ v_printf(char *, ...);
int /*<<< orphan*/ write(int, char *, int);
int process(const int rounds, const int num_files, const int write_size,
            const int write_iters) {
  int failed = 0;
  int fd[num_files];
  struct stat fsbuf[num_files];
  struct stat sbuf[num_files];
  char ch = 'A';
  char buf[write_size];
  char basename[4096];
  char filename[4096];
  int sret;
  int fsret;
  v_printf("r%d n%d s%d i%d\n", rounds, num_files, write_size, write_iters);
  for (int idx = 0; idx < write_size; idx++) {
    buf[idx] = ch;
    ++ch;
    if (ch > 'z')
      ch = 'A';
  }
  strcpy(basename, "files/stat-vs-fstat-");
  for (int idx = 1; idx <= num_files; idx++) {
    sprintf(filename, "%s%d", basename, idx - 1);
    fd[idx] = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0);
    for (int kdx = 0; kdx < write_iters; kdx++) {
      write(fd[idx], buf, idx * write_size);
    }
  }
  for (int idx = 1; idx <= num_files; idx++) {
    sprintf(filename, "%s%d", basename, idx);
    fsret = fstat(fd[idx], &fsbuf[idx]);
    if (fsret < 0 || sret < 0) {
      v_printf("ERROR on stat or fstat\n");
      ++failed;
    } else {
      int expected_size;
      expected_size = idx * write_size * write_iters;
      if (fsbuf[idx].st_size == expected_size) {
        v_printf(
            "stat-vs-fstat-%d After write, fstat got expected size of %d\n",
            idx, fsbuf[idx].st_size);
      } else {
        v_printf("stat-vs-fstat-%d After write, fstat ERROR expected %d size "
                 "is %d\n",
                 idx, expected_size, fsbuf[idx].st_size);
        ++failed;
      }
    }
    close(fd[idx]);
  }
  return failed;
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2090,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2088(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2080(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movb   $0x41,-0x39(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2078(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1080 <v_printf@plt>
movl   $0x0,-0x205c(%rbp)
mov    -0x205c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1297 <process+0x127>
mov    -0x2078(%rbp),%rax
mov    -0x39(%rbp),%dl
movslq -0x205c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x39(%rbp),%al
add    $0x1,%al
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
cmp    $0x7a,%eax
jle    127e <process+0x10e>
movb   $0x41,-0x39(%rbp)
jmp    1283 <process+0x113>
mov    -0x205c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x205c(%rbp)
jmp    1242 <process+0xd2>
lea    -0x1050(%rbp),%rdi
lea    0xd6c(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x2060(%rbp)
mov    -0x2060(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     138f <process+0x21f>
lea    -0x2050(%rbp),%rdi
lea    -0x1050(%rbp),%rdx
mov    -0x2060(%rbp),%ecx
sub    $0x1,%ecx
lea    0xd45(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x2050(%rbp),%rdi
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
mov    0x2cfb(%rip),%rax
or     (%rax),%esi
mov    0x2cea(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,%edx
mov    -0x2088(%rbp),%rax
movslq -0x2060(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0x0,-0x2064(%rbp)
mov    -0x2064(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1376 <process+0x206>
mov    -0x2078(%rbp),%rsi
mov    -0x2088(%rbp),%rax
movslq -0x2060(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x2060(%rbp),%edx
imul   -0xc(%rbp),%edx
call   1040 <write@plt>
mov    -0x2064(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2064(%rbp)
jmp    132c <process+0x1bc>
jmp    137b <process+0x20b>
mov    -0x2060(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2060(%rbp)
jmp    12b4 <process+0x144>
movl   $0x1,-0x2068(%rbp)
mov    -0x2068(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     14ed <process+0x37d>
lea    -0x2050(%rbp),%rdi
lea    -0x1050(%rbp),%rdx
mov    -0x2068(%rbp),%ecx
lea    0xc63(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x2080(%rbp),%rsi
mov    -0x2088(%rbp),%rax
movslq -0x2068(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
movslq -0x2068(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1090 <fstat@plt>
mov    %eax,-0x2058(%rbp)
cmpl   $0x0,-0x2058(%rbp)
jl     1413 <process+0x2a3>
cmpl   $0x0,-0x2054(%rbp)
jge    142f <process+0x2bf>
lea    0xc11(%rip),%rdi
mov    $0x0,%al
call   1080 <v_printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14c3 <process+0x353>
mov    -0x2080(%rbp),%rax
mov    -0x2068(%rbp),%ecx
imul   -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
mov    %ecx,-0x206c(%rbp)
movslq -0x2068(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x206c(%rbp),%eax
jne    148a <process+0x31a>
mov    -0x2080(%rbp),%rax
mov    -0x2068(%rbp),%esi
movslq -0x2068(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xbc5(%rip),%rdi
mov    $0x0,%al
call   1080 <v_printf@plt>
jmp    14be <process+0x34e>
mov    -0x2080(%rbp),%rax
mov    -0x2068(%rbp),%esi
mov    -0x206c(%rbp),%edx
movslq -0x2068(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xbd2(%rip),%rdi
mov    $0x0,%al
call   1080 <v_printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    14c3 <process+0x353>
mov    -0x2088(%rbp),%rax
movslq -0x2068(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <close@plt>
mov    -0x2068(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2068(%rbp)
jmp    1399 <process+0x229>
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2038,%rsp
mov    %ecx,%r8d
mov    %edx,%r12d
mov    %esi,%edx
mov    %edi,%esi
mov    %edx,%r13d
mov    %rsp,%rcx
lea    0xf(,%r13,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %r12d,%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe32(%rip),%rdi
movl   $0x0,-0x38(%rbp)
mov    %rdx,-0x50(%rbp)
mov    %r12d,%ecx
mov    %r8d,-0x2c(%rbp)
xor    %eax,%eax
call   1080 <v_printf@plt>
mov    %r12d,-0x3c(%rbp)
test   %r12d,%r12d
jle    1238 <process+0xc8>
lea    -0x1(%r14),%rax
mov    %r14d,%r8d
and    $0x3,%r8d
cmp    $0x3,%rax
jae    13e8 <process+0x278>
mov    $0x41,%dl
xor    %ecx,%ecx
test   %r8,%r8
je     1238 <process+0xc8>
add    %rbx,%rcx
xor    %esi,%esi
mov    $0x41,%edi
nopl   0x0(%rax,%rax,1)
mov    %dl,(%rcx,%rsi,1)
add    $0x1,%dl
cmp    $0x7b,%dl
movzbl %dl,%edx
cmovge %edi,%edx
add    $0x1,%rsi
cmp    %rsi,%r8
jne    1220 <process+0xb0>
mov    %r15,-0x60(%rbp)
lea    0xdce(%rip),%rsi
lea    -0x1060(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rax
test   %eax,%eax
jle    146b <process+0x2fb>
mov    %r13,-0x38(%rbp)
add    $0x1,%eax
mov    %rax,-0x48(%rbp)
mov    $0x1,%r15d
jmp    127a <process+0x10a>
xchg   %ax,%ax
add    $0x1,%r15
cmp    -0x48(%rbp),%r15
je     12f9 <process+0x189>
lea    -0x1(%r15),%ecx
lea    -0x2060(%rbp),%r14
mov    %r14,%rdi
lea    0xd97(%rip),%rsi
lea    -0x1060(%rbp),%rdx
call   1070 <sprintf@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
mov    0x2d2d(%rip),%rax
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,%r12d
mov    -0x58(%rbp),%rax
mov    %r12d,(%rax,%r15,4)
cmpl   $0x0,-0x2c(%rbp)
jle    1270 <process+0x100>
mov    %r15d,%r14d
imul   -0x3c(%rbp),%r14d
mov    -0x2c(%rbp),%r13d
nopl   (%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <write@plt>
add    $0xffffffff,%r13d
jne    12e0 <process+0x170>
jmp    1270 <process+0x100>
cmpl   $0x0,-0x50(%rbp)
jle    1464 <process+0x2f4>
mov    -0x2c(%rbp),%r13d
imul   -0x3c(%rbp),%r13d
mov    -0x38(%rbp),%rax
lea    0x4(,%rax,4),%rax
mov    %rax,-0x48(%rbp)
mov    $0x1,%ebx
mov    $0x4,%r12d
mov    %r13d,-0x2c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x60(%rbp),%r15
jmp    136f <process+0x1ff>
nopl   0x0(%rax,%rax,1)
lea    0xce4(%rip),%rdi
xor    %eax,%eax
call   1080 <v_printf@plt>
addl   $0x1,-0x38(%rbp)
mov    %r14d,%edi
call   1050 <close@plt>
add    $0x1,%ebx
add    -0x2c(%rbp),%r13d
add    $0x4,%r12
cmp    %r12,-0x48(%rbp)
je     146b <process+0x2fb>
lea    -0x2060(%rbp),%rdi
lea    0xca9(%rip),%rsi
lea    -0x1060(%rbp),%rdx
mov    %ebx,%ecx
call   1070 <sprintf@plt>
mov    -0x58(%rbp),%rax
mov    (%rax,%r12,1),%r14d
lea    (%r15,%r12,1),%rsi
mov    %r14d,%edi
call   1090 <fstat@plt>
test   %eax,%eax
js     1340 <process+0x1d0>
mov    (%r15,%r12,1),%ecx
cmp    %ecx,%r13d
jne    13d0 <process+0x260>
lea    0xc90(%rip),%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1080 <v_printf@plt>
jmp    1352 <process+0x1e2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xca9(%rip),%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1080 <v_printf@plt>
jmp    134e <process+0x1de>
and    $0xfffffffc,%r14d
mov    $0x41,%al
xor    %ecx,%ecx
jmp    140f <process+0x29f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x4,%rcx
mov    %edx,%eax
cmp    %rcx,%r14
je     1209 <process+0x99>
mov    %al,(%rbx,%rcx,1)
add    $0x1,%al
mov    $0x41,%edx
mov    $0x41,%esi
cmp    $0x7b,%al
jge    1425 <process+0x2b5>
movzbl %al,%esi
mov    %sil,0x1(%rbx,%rcx,1)
add    $0x1,%sil
mov    $0x41,%eax
cmp    $0x7b,%sil
jge    143d <process+0x2cd>
movzbl %sil,%eax
mov    %al,0x2(%rbx,%rcx,1)
add    $0x1,%al
mov    $0x41,%esi
cmp    $0x7b,%al
jge    144f <process+0x2df>
movzbl %al,%esi
mov    %sil,0x3(%rbx,%rcx,1)
add    $0x1,%sil
cmp    $0x7b,%sil
jge    1400 <process+0x290>
movzbl %sil,%edx
jmp    1400 <process+0x290>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"r%d n%d s%d i%d\0A\00"
@.str.1 = [21 x i8] c"files/stat-vs-fstat-\00"
@.str.2 = [5 x i8] c"%s%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [24 x i8] c"ERROR on stat or fstat\0A\00"
@.str.4 = [61 x i8] c"stat-vs-fstat-%d After write, fstat got expected size of %d\0A\00"
@.str.5 = [66 x i8] c"stat-vs-fstat-%d After write, fstat ERROR expected %d size is %d\0A\00"
define i32 @process(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8
%15 = alloca i64
%16 = alloca [4096 x i8]
%17 = alloca [4096 x i8]
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %10
%28 = alloca i32, i64 %26
store i64 %26, i64* %11
%29 = load i32, i32* %6
%30 = zext i32 %29 to i64
%31 = alloca %struct.stat, i64 %30
store i64 %30, i64* %12
%32 = load i32, i32* %6
%33 = zext i32 %32 to i64
%34 = alloca %struct.stat, i64 %33
store i64 %33, i64* %13
store i8 65, i8* %14
%35 = load i32, i32* %7
%36 = zext i32 %35 to i64
%37 = alloca i8, i64 %36
store i64 %36, i64* %15
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %41)
store i32 0, i32* %20
br label %43
43: ; preds = %59, %4
%44 = load i32, i32* %20
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %62
47: ; preds = %43
%48 = load i8, i8* %14
%49 = load i32, i32* %20
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %37, i64 %50
store i8 %48, i8* %51
%52 = load i8, i8* %14
%53 = add i8 %52, 1
store i8 %53, i8* %14
%54 = load i8, i8* %14
%55 = sext i8 %54 to i32
%56 = icmp sgt i32 %55, 122
br i1 %56, label %57, label %58
57: ; preds = %47
store i8 65, i8* %14
br label %58
58: ; preds = %57, %47
br label %59
59: ; preds = %58
%60 = load i32, i32* %20
%61 = add nsw i32 %60, 1
store i32 %61, i32* %20
br label %43
62: ; preds = %43
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%64 = call i32 @strcpy(i8* %63, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %21
br label %65
65: ; preds = %102, %62
%66 = load i32, i32* %21
%67 = load i32, i32* %6
%68 = icmp sle i32 %66, %67
br i1 %68, label %69, label %105
69: ; preds = %65
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%71 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%72 = load i32, i32* %21
%73 = sub nsw i32 %72, 1
%74 = call i32 @sprintf(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %71, i32 %73)
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%76 = load i32, i32* @O_RDWR
%77 = load i32, i32* @O_CREAT
%78 = or i32 %76, %77
%79 = load i32, i32* @O_TRUNC
%80 = or i32 %78, %79
%81 = call i32 @open(i8* %75, i32 %80, i32 0)
%82 = load i32, i32* %21
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %28, i64 %83
store i32 %81, i32* %84
store i32 0, i32* %22
br label %85
85: ; preds = %98, %69
%86 = load i32, i32* %22
%87 = load i32, i32* %8
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %101
89: ; preds = %85
%90 = load i32, i32* %21
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %28, i64 %91
%93 = load i32, i32* %92
%94 = load i32, i32* %21
%95 = load i32, i32* %7
%96 = mul nsw i32 %94, %95
%97 = call i32 @write(i32 %93, i8* %37, i32 %96)
br label %98
98: ; preds = %89
%99 = load i32, i32* %22
%100 = add nsw i32 %99, 1
store i32 %100, i32* %22
br label %85
101: ; preds = %85
br label %102
102: ; preds = %101
%103 = load i32, i32* %21
%104 = add nsw i32 %103, 1
store i32 %104, i32* %21
br label %65
105: ; preds = %65
store i32 1, i32* %23
br label %106
106: ; preds = %171, %105
%107 = load i32, i32* %23
%108 = load i32, i32* %6
%109 = icmp sle i32 %107, %108
br i1 %109, label %110, label %174
110: ; preds = %106
%111 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%112 = getelementptr inbounds [4096 x i8], [4096 x i8]* %16, i64 0, i64 0
%113 = load i32, i32* %23
%114 = call i32 @sprintf(i8* %111, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %112, i32 %113)
%115 = load i32, i32* %23
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %28, i64 %116
%118 = load i32, i32* %117
%119 = load i32, i32* %23
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds %struct.stat, %struct.stat* %31, i64 %120
%122 = call i32 @fstat(i32 %118, %struct.stat* %121)
store i32 %122, i32* %19
%123 = load i32, i32* %19
%124 = icmp slt i32 %123, 0
br i1 %124, label %128, label %125
125: ; preds = %110
%126 = load i32, i32* %18
%127 = icmp slt i32 %126, 0
br i1 %127, label %128, label %132
128: ; preds = %125, %110
%129 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%130 = load i32, i32* %9
%131 = add nsw i32 %130, 1
store i32 %131, i32* %9
br label %165
132: ; preds = %125
%133 = load i32, i32* %23
%134 = load i32, i32* %7
%135 = mul nsw i32 %133, %134
%136 = load i32, i32* %8
%137 = mul nsw i32 %135, %136
store i32 %137, i32* %24
%138 = load i32, i32* %23
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds %struct.stat, %struct.stat* %31, i64 %139
%141 = getelementptr inbounds %struct.stat, %struct.stat* %140, i32 0, i32 0
%142 = load i32, i32* %141
%143 = load i32, i32* %24
%144 = icmp eq i32 %142, %143
br i1 %144, label %145, label %153
145: ; preds = %132
%146 = load i32, i32* %23
%147 = load i32, i32* %23
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds %struct.stat, %struct.stat* %31, i64 %148
%150 = getelementptr inbounds %struct.stat, %struct.stat* %149, i32 0, i32 0
%151 = load i32, i32* %150
%152 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %146, i32 %151)
br label %164
153: ; preds = %132
%154 = load i32, i32* %23
%155 = load i32, i32* %24
%156 = load i32, i32* %23
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds %struct.stat, %struct.stat* %31, i64 %157
%159 = getelementptr inbounds %struct.stat, %struct.stat* %158, i32 0, i32 0
%160 = load i32, i32* %159
%161 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.5, i64 0, i64 0), i32 %154, i32 %155, i32 %160)
%162 = load i32, i32* %9
%163 = add nsw i32 %162, 1
store i32 %163, i32* %9
br label %164
164: ; preds = %153, %145
br label %165
165: ; preds = %164, %128
%166 = load i32, i32* %23
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i32, i32* %28, i64 %167
%169 = load i32, i32* %168
%170 = call i32 @close(i32 %169)
br label %171
171: ; preds = %165
%172 = load i32, i32* %23
%173 = add nsw i32 %172, 1
store i32 %173, i32* %23
br label %106
174: ; preds = %106
%175 = load i32, i32* %9
%176 = load i8*, i8** %10
ret i32 %175
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"r%d n%d s%d i%d\0A\00"
@.str.1 = [21 x i8] c"files/stat-vs-fstat-\00"
@.str.2 = [5 x i8] c"%s%d\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [24 x i8] c"ERROR on stat or fstat\0A\00"
@.str.4 = [61 x i8] c"stat-vs-fstat-%d After write, fstat got expected size of %d\0A\00"
@.str.5 = [66 x i8] c"stat-vs-fstat-%d After write, fstat ERROR expected %d size is %d\0A\00"
define i32 @process(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = zext i32 %1 to i64
%8 = alloca i32, i64 %7
%9 = alloca %struct.stat, i64 %7
%10 = zext i32 %2 to i64
%11 = alloca i8, i64 %10
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%14 = tail call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i32 %2, i32 %3)
%15 = icmp sgt i32 %2, 0
br i1 %15, label %16, label %37
16: ; preds = %4
%17 = add nsw i64 %10, -1
%18 = and i64 %10, 3
%19 = icmp ult i64 %17, 3
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = and i64 %10, 4294967292
br label %44
22: ; preds = %44, %16
%23 = phi i64 [ 0, %16 ], [ %67, %44 ]
%24 = phi i8 [ 65, %16 ], [ %66, %44 ]
%25 = icmp eq i64 %18, 0
br i1 %25, label %37, label %26
26: ; preds = %22, %26
%27 = phi i64 [ %34, %26 ], [ %23, %22 ]
%28 = phi i8 [ %33, %26 ], [ %24, %22 ]
%29 = phi i64 [ %35, %26 ], [ 0, %22 ]
%30 = getelementptr inbounds i8, i8* %11, i64 %27
store i8 %28, i8* %30
%31 = add i8 %28, 1
%32 = icmp sgt i8 %31, 122
%33 = select i1 %32, i8 65, i8 %31
%34 = add nuw nsw i64 %27, 1
%35 = add i64 %29, 1
%36 = icmp eq i64 %35, %18
br i1 %36, label %37, label %26
37: ; preds = %22, %26, %4
%38 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp slt i32 %1, 1
br i1 %39, label %98, label %40
40: ; preds = %37
%41 = icmp sgt i32 %3, 0
%42 = add nuw i32 %1, 1
%43 = zext i32 %42 to i64
br label %75
44: ; preds = %44, %20
%45 = phi i64 [ 0, %20 ], [ %67, %44 ]
%46 = phi i8 [ 65, %20 ], [ %66, %44 ]
%47 = phi i64 [ 0, %20 ], [ %68, %44 ]
%48 = getelementptr inbounds i8, i8* %11, i64 %45
store i8 %46, i8* %48
%49 = add i8 %46, 1
%50 = icmp sgt i8 %49, 122
%51 = select i1 %50, i8 65, i8 %49
%52 = or i64 %45, 1
%53 = getelementptr inbounds i8, i8* %11, i64 %52
store i8 %51, i8* %53
%54 = add i8 %51, 1
%55 = icmp sgt i8 %54, 122
%56 = select i1 %55, i8 65, i8 %54
%57 = or i64 %45, 2
%58 = getelementptr inbounds i8, i8* %11, i64 %57
store i8 %56, i8* %58
%59 = add i8 %56, 1
%60 = icmp sgt i8 %59, 122
%61 = select i1 %60, i8 65, i8 %59
%62 = or i64 %45, 3
%63 = getelementptr inbounds i8, i8* %11, i64 %62
store i8 %61, i8* %63
%64 = add i8 %61, 1
%65 = icmp sgt i8 %64, 122
%66 = select i1 %65, i8 65, i8 %64
%67 = add nuw nsw i64 %45, 4
%68 = add i64 %47, 4
%69 = icmp eq i64 %68, %21
br i1 %69, label %22, label %44
70: ; preds = %90
br i1 %39, label %98, label %71
71: ; preds = %70
%72 = mul i32 %3, %2
%73 = add nuw i32 %1, 1
%74 = zext i32 %73 to i64
br label %100
75: ; preds = %40, %90
%76 = phi i64 [ 1, %40 ], [ %91, %90 ]
%77 = trunc i64 %76 to i32
%78 = add i32 %77, -1
%79 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %78)
%80 = load i32, i32* @O_RDWR
%81 = load i32, i32* @O_CREAT
%82 = or i32 %81, %80
%83 = load i32, i32* @O_TRUNC
%84 = or i32 %82, %83
%85 = call i32 @open(i8* %13, i32 %84, i32 0)
%86 = getelementptr inbounds i32, i32* %8, i64 %76
store i32 %85, i32* %86
br i1 %41, label %87, label %90
87: ; preds = %75
%88 = trunc i64 %76 to i32
%89 = mul nsw i32 %88, %2
br label %93
90: ; preds = %93, %75
%91 = add nuw nsw i64 %76, 1
%92 = icmp eq i64 %91, %43
br i1 %92, label %70, label %75
93: ; preds = %87, %93
%94 = phi i32 [ 0, %87 ], [ %96, %93 ]
%95 = call i32 @write(i32 %85, i8* %11, i32 %89)
%96 = add nuw nsw i32 %94, 1
%97 = icmp eq i32 %96, %3
br i1 %97, label %90, label %93
98: ; preds = %123, %37, %70
%99 = phi i32 [ 0, %70 ], [ 0, %37 ], [ %124, %123 ]
ret i32 %99
100: ; preds = %71, %123
%101 = phi i64 [ 1, %71 ], [ %126, %123 ]
%102 = phi i32 [ 0, %71 ], [ %124, %123 ]
%103 = trunc i64 %101 to i32
%104 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %103)
%105 = getelementptr inbounds i32, i32* %8, i64 %101
%106 = load i32, i32* %105
%107 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 %101
%108 = call i32 @fstat(i32 %106, %struct.stat* %107)
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %113
110: ; preds = %100
%111 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%112 = add nsw i32 %102, 1
br label %123
113: ; preds = %100
%114 = mul i32 %72, %103
%115 = getelementptr inbounds %struct.stat, %struct.stat* %107, i64 0, i32 0
%116 = load i32, i32* %115
%117 = icmp eq i32 %116, %114
br i1 %117, label %118, label %120
118: ; preds = %113
%119 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %103, i32 %114)
br label %123
120: ; preds = %113
%121 = call i32 (i8*, ...) @v_printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.5, i64 0, i64 0), i32 %103, i32 %114, i32 %116)
%122 = add nsw i32 %102, 1
br label %123
123: ; preds = %118, %120, %110
%124 = phi i32 [ %112, %110 ], [ %102, %118 ], [ %122, %120 ]
%125 = call i32 @close(i32 %106)
%126 = add nuw nsw i64 %101, 1
%127 = icmp eq i64 %126, %74
br i1 %127, label %98, label %100
}