#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ os_usleep(unsigned long const);
FILE *my_fopen(const char *filename, const char *mode, const int nb_retries,
               const unsigned long int usec_delay) {
  int retry;
  FILE *f = NULL;
  for (retry = 1; retry <= nb_retries; ++retry, os_usleep(usec_delay)) {
    if ((f = fopen(filename, mode)) != NULL)
      break;
  }
  return f;
}


x86 assembly (clang, -O0):
<my_fopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     118e <my_fopen+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1172 <my_fopen+0x52>
jmp    118e <my_fopen+0x6e>
jmp    1177 <my_fopen+0x57>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <os_usleep@plt>
jmp    1146 <my_fopen+0x26>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_fopen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    115d <my_fopen+0x3d>
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <fopen@plt>
test   %rax,%rax
jne    115f <my_fopen+0x3f>
mov    %r14,%rdi
call   1030 <os_usleep@plt>
add    $0xffffffff,%ebp
jne    1140 <my_fopen+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @my_fopen(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i64 %3, i64* %8
store i32* null, i32** %10
store i32 1, i32* %9
br label %11
11: ; preds = %22, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %7
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8*, i8** %6
%18 = call i32* @fopen(i8* %16, i8* %17)
store i32* %18, i32** %10
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %15
br label %27
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 1
store i32 %24, i32* %9
%25 = load i64, i64* %8
%26 = call i32 @os_usleep(i64 %25)
br label %11
27: ; preds = %20, %11
%28 = load i32*, i32** %10
ret i32* %28
}

LLVM IR (-O2):
define noalias i32* @my_fopen(i8* nocapture %0, i8* nocapture %1, i32 %2, i64 %3) {
%5 = icmp slt i32 %2, 1
br i1 %5, label %14, label %6
6: ; preds = %4, %10
%7 = phi i32 [ %11, %10 ], [ 1, %4 ]
%8 = tail call i32* @fopen(i8* %0, i8* %1)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = add nuw i32 %7, 1
%12 = tail call i32 @os_usleep(i64 %3)
%13 = icmp eq i32 %7, %2
br i1 %13, label %14, label %6
14: ; preds = %10, %6, %4
%15 = phi i32* [ null, %4 ], [ %8, %6 ], [ null, %10 ]
ret i32* %15
}