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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fstat(int, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  struct stat sb[3];
  for (int i = 0; i < 3; i++) {
    int err = fstat(i, &sb[i]);
    if (err < 0) {
      perror("fstat");
      exit(1);
    } else
      printf("fstat %d success!\n", i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11bc <main+0x7c>
mov    -0x14(%rbp),%edi
movslq -0x14(%rbp),%rax
lea    -0x10(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
call   1060 <fstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    119a <main+0x5a>
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
jmp    11ae <main+0x6e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1060 <fstat@plt>
test   %eax,%eax
js     11b1 <main+0x71>
lea    0xeab(%rip),%rdi
xor    %esi,%esi
call   1030 <printf@plt>
lea    0xc(%rsp),%rsi
mov    $0x1,%edi
call   1060 <fstat@plt>
test   %eax,%eax
js     11b1 <main+0x71>
lea    0xe8a(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0x10(%rsp),%rsi
mov    $0x2,%edi
call   1060 <fstat@plt>
test   %eax,%eax
js     11b1 <main+0x71>
lea    0xe66(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe48(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"fstat\00"
@.str.1 = [19 x i8] c"fstat %d success!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x %struct.stat]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %23, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 3
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = load i32, i32* %3
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [3 x %struct.stat], [3 x %struct.stat]* %2, i64 0, i64 %11
%13 = call i32 @fstat(i32 %9, %struct.stat* %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = load i32, i32* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %5
26: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"fstat\00"
@.str.1 = [19 x i8] c"fstat %d success!\0A\00"
define i32 @main() {
%1 = alloca [3 x %struct.stat]
%2 = bitcast [3 x %struct.stat]* %1 to i8*
%3 = getelementptr inbounds [3 x %struct.stat], [3 x %struct.stat]* %1, i64 0, i64 0
%4 = call i32 @fstat(i32 0, %struct.stat* %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %14, %9, %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 0)
%11 = getelementptr inbounds [3 x %struct.stat], [3 x %struct.stat]* %1, i64 0, i64 1
%12 = call i32 @fstat(i32 1, %struct.stat* %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %9
%15 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 1)
%16 = getelementptr inbounds [3 x %struct.stat], [3 x %struct.stat]* %1, i64 0, i64 2
%17 = call i32 @fstat(i32 2, %struct.stat* %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %6, label %19
19: ; preds = %14
%20 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 2)
ret i32 0
}