#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*/ errno;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int stat(char const *, struct stat *);
char *strerror(int /*<<< orphan*/);
int device_recovery_start() {
  const char *fn = "/dev/block/platform/mmci-omap-hs.0/by-name/userdata";
  int tries = 0;
  int ret;
  struct stat buf;
  do {
    ++tries;
    ret = stat(fn, &buf);
    if (ret) {
      printf("try %d: %s\n", tries, strerror(errno));
      sleep(1);
    }
  } while (ret && tries < 5);
  if (!ret) {
    printf("stat() of %s succeeded on try %d\n", fn, tries);
  } else {
    printf("failed to stat %s\n", fn);
  }
  return 0;
}


x86 assembly (clang, -O0):
<device_recovery_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11af <device_recovery_start+0x6f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%esi
mov    %rax,%rdx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11b4 <device_recovery_start+0x74>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
je     11cd <device_recovery_start+0x8d>
cmpl   $0x5,-0xc(%rbp)
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115a <device_recovery_start+0x1a>
cmpl   $0x0,-0x10(%rbp)
jne    11fc <device_recovery_start+0xbc>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120e <device_recovery_start+0xce>
mov    -0x8(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device_recovery_start>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     129f <device_recovery_start+0x15f>
mov    0x2e7b(%rip),%rbx
mov    (%rbx),%edi
call   1050 <strerror@plt>
lea    0xec1(%rip),%rdi
mov    $0x1,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe6d(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     12a6 <device_recovery_start+0x166>
mov    (%rbx),%edi
call   1050 <strerror@plt>
lea    0xe81(%rip),%rdi
mov    $0x2,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe2d(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     12ad <device_recovery_start+0x16d>
mov    (%rbx),%edi
call   1050 <strerror@plt>
lea    0xe41(%rip),%rdi
mov    $0x3,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xded(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     12b4 <device_recovery_start+0x174>
mov    (%rbx),%edi
call   1050 <strerror@plt>
lea    0xe01(%rip),%rdi
mov    $0x4,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xdad(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     12bb <device_recovery_start+0x17b>
mov    (%rbx),%edi
call   1050 <strerror@plt>
lea    0xdc5(%rip),%rdi
mov    $0x5,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xdd3(%rip),%rdi
lea    0xd6a(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12d5 <device_recovery_start+0x195>
mov    $0x1,%edx
jmp    12c0 <device_recovery_start+0x180>
mov    $0x2,%edx
jmp    12c0 <device_recovery_start+0x180>
mov    $0x3,%edx
jmp    12c0 <device_recovery_start+0x180>
mov    $0x4,%edx
jmp    12c0 <device_recovery_start+0x180>
mov    $0x5,%edx
lea    0xd79(%rip),%rdi
lea    0xd32(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [52 x i8] c"/dev/block/platform/mmci-omap-hs.0/by-name/userdata\00"
@.str.1 = [12 x i8] c"try %d: %s\0A\00"
@errno = global i32 0
@.str.2 = [34 x i8] c"stat() of %s succeeded on try %d\0A\00"
@.str.3 = [19 x i8] c"failed to stat %s\0A\00"
define i32 @device_recovery_start() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.stat
store i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8** %1
store i32 0, i32* %2
br label %5
5: ; preds = %25, %0
%6 = load i32, i32* %2
%7 = add nsw i32 %6, 1
store i32 %7, i32* %2
%8 = load i8*, i8** %1
%9 = call i32 @stat(i8* %8, %struct.stat* %4)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %5
%13 = load i32, i32* %2
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %15)
%17 = call i32 @sleep(i32 1)
br label %18
18: ; preds = %12, %5
br label %19
19: ; preds = %18
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 5
br label %25
25: ; preds = %22, %19
%26 = phi i1 [ false, %19 ], [ %24, %22 ]
br i1 %26, label %5, label %27
27: ; preds = %25
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i8*, i8** %1
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32)
br label %37
34: ; preds = %27
%35 = load i8*, i8** %1
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %34, %30
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [52 x i8] c"/dev/block/platform/mmci-omap-hs.0/by-name/userdata\00"
@.str.1 = [12 x i8] c"try %d: %s\0A\00"
@errno = global i32 0
@.str.2 = [34 x i8] c"stat() of %s succeeded on try %d\0A\00"
@.str.3 = [19 x i8] c"failed to stat %s\0A\00"
define i32 @device_recovery_start() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @stat(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %39, label %5
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 1, i8* %7)
%9 = tail call i32 @sleep(i32 1)
%10 = call i32 @stat(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %39, label %12
12: ; preds = %5
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 2, i8* %14)
%16 = tail call i32 @sleep(i32 1)
%17 = call i32 @stat(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%18 = icmp eq i32 %17, 0
br i1 %18, label %39, label %19
19: ; preds = %12
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 3, i8* %21)
%23 = tail call i32 @sleep(i32 1)
%24 = call i32 @stat(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%25 = icmp eq i32 %24, 0
br i1 %25, label %39, label %26
26: ; preds = %19
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 4, i8* %28)
%30 = tail call i32 @sleep(i32 1)
%31 = call i32 @stat(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%32 = icmp eq i32 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %26
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 5, i8* %35)
%37 = tail call i32 @sleep(i32 1)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %42
39: ; preds = %26, %19, %12, %5, %0
%40 = phi i32 [ 1, %0 ], [ 2, %5 ], [ 3, %12 ], [ 4, %19 ], [ 5, %26 ]
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %33, %39
ret i32 0
}