#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 otp_info {
  int start;
  int length;
  scalar_t__ locked;
};

/* Variables and functions */
int EINVAL;
int MTD_OTP_FACTORY;
int MTD_OTP_USER;
int /*<<< orphan*/ OTPGETREGIONCOUNT;
int /*<<< orphan*/ OTPGETREGIONINFO;
int /*<<< orphan*/ OTPSELECT;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int fd, val, i, ret;
  if (argc != 3 || (strcmp(argv[1], "-f") && strcmp(argv[1], "-u"))) {
    fprintf(stderr, "Usage: %s [ -f | -u ] <device>\n", "flash_otp_info");
    return EINVAL;
  }
  fd = open(argv[2], O_RDONLY);
  if (fd < 0) {
    perror(argv[2]);
    return errno;
  }
  val = argv[1][1] == 'f' ? MTD_OTP_FACTORY : MTD_OTP_USER;
  ret = ioctl(fd, OTPSELECT, &val);
  if (ret < 0) {
    perror("OTPSELECT");
    return errno;
  }
  ret = ioctl(fd, OTPGETREGIONCOUNT, &val);
  if (ret < 0) {
    perror("OTPGETREGIONCOUNT");
    return errno;
  }
  printf("Number of OTP %s blocks on %s: %d\n",
         argv[1][1] == 'f' ? "factory" : "user", argv[2], val);
  if (val > 0) {
    struct otp_info info[val];
    ret = ioctl(fd, OTPGETREGIONINFO, &info);
    if (ret < 0) {
      perror("OTPGETREGIONCOUNT");
      return errno;
    }
    for (i = 0; i < val; i++)
      printf("block %2d:  offset = 0x%04x  "
             "size = %2d bytes  %s\n",
             i, info[i].start, info[i].length,
             info[i].locked ? "[locked]" : "[unlocked]");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    11cc <main+0x5c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe46(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f9 <main+0x89>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
lea    0xe43(%rip),%rdx
call   1070 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1451 <main+0x2e1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <perror@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1451 <main+0x2e1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x66,%eax
jne    1260 <main+0xf0>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
jmp    126c <main+0xfc>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12b3 <main+0x143>
lea    0xd98(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1451 <main+0x2e1>
mov    -0x14(%rbp),%edi
mov    0x2cf3(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12f4 <main+0x184>
lea    0xd61(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1451 <main+0x2e1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%ecx
lea    0xd75(%rip),%rsi
lea    0xd66(%rip),%rax
cmp    $0x66,%ecx
cmove  %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x18(%rbp),%ecx
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jle    1442 <main+0x2d2>
mov    -0x18(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
shl    $0x4,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c64(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    139e <main+0x22e>
lea    0xcbe(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1421 <main+0x2b1>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    141a <main+0x2aa>
mov    -0x40(%rbp),%rax
mov    -0x1c(%rbp),%esi
movslq -0x1c(%rbp),%rdx
shl    $0x4,%rdx
mov    %rax,%rcx
add    %rdx,%rcx
mov    (%rcx),%edx
movslq -0x1c(%rbp),%rdi
shl    $0x4,%rdi
mov    %rax,%rcx
add    %rdi,%rcx
mov    0x4(%rcx),%ecx
movslq -0x1c(%rbp),%rdi
shl    $0x4,%rdi
add    %rdi,%rax
mov    0x8(%rax),%rdi
lea    0xcce(%rip),%r8
lea    0xcbe(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%r8
lea    0xc7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13a5 <main+0x235>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     143d <main+0x2cd>
jmp    1438 <main+0x2c8>
jmp    1451 <main+0x2e1>
jmp    1442 <main+0x2d2>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    11b3 <main+0x43>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11dd <main+0x6d>
mov    0x8(%rbx),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11dd <main+0x6d>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
lea    0xe5c(%rip),%rdx
call   1070 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%ebx
jmp    1333 <main+0x1c3>
mov    0x10(%rbx),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1344 <main+0x1d4>
mov    %eax,%r14d
mov    0x8(%rbx),%rax
cmpb   $0x66,0x1(%rax)
jne    120d <main+0x9d>
mov    0x2ded(%rip),%rax
jmp    1214 <main+0xa4>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %eax,%eax
js     134a <main+0x1da>
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %eax,%eax
js     1353 <main+0x1e3>
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%rdx
cmpb   $0x66,0x1(%rax)
lea    0xe0a(%rip),%rax
lea    0xe0b(%rip),%rsi
cmove  %rax,%rsi
mov    -0x2c(%rbp),%ecx
lea    0xdd2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    132b <main+0x1bb>
mov    %rsp,%r15
mov    %rsp,%r13
shl    $0x4,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <ioctl@plt>
test   %eax,%eax
js     136a <main+0x1fa>
mov    %r15,-0x38(%rbp)
mov    %r14d,-0x30(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    1321 <main+0x1b1>
add    $0x8,%r13
lea    0xde3(%rip),%r14
lea    0xdd3(%rip),%r15
lea    0xd99(%rip),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    -0x8(%r13),%edx
mov    -0x4(%r13),%ecx
cmpq   $0x0,0x0(%r13)
mov    %r15,%r8
cmove  %r14,%r8
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    $0x10,%r13
cmp    %rax,%rbx
jl     12f0 <main+0x180>
mov    -0x38(%rbp),%rsp
mov    -0x30(%rbp),%r14d
xor    %ebx,%ebx
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rbx),%rdi
jmp    135a <main+0x1ea>
lea    0xce4(%rip),%rdi
jmp    135a <main+0x1ea>
lea    0xce5(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%ebx
jmp    1333 <main+0x1c3>
lea    0xcce(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c2b(%rip),%rax
mov    (%rax),%ebx
mov    %r15,%rsp
jmp    1333 <main+0x1c3>

LLVM IR (-O0):
%struct.otp_info = type { i32, i32, i64 }
@.str = [3 x i8] c"-f\00"
@.str.1 = [3 x i8] c"-u\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Usage: %s [ -f | -u ] <device>\0A\00"
@.str.3 = [15 x i8] c"flash_otp_info\00"
@EINVAL = global i32 0
@O_RDONLY = global i32 0
@errno = global i32 0
@MTD_OTP_FACTORY = global i32 0
@MTD_OTP_USER = global i32 0
@OTPSELECT = global i32 0
@.str.4 = [10 x i8] c"OTPSELECT\00"
@OTPGETREGIONCOUNT = global i32 0
@.str.5 = [18 x i8] c"OTPGETREGIONCOUNT\00"
@.str.6 = [35 x i8] c"Number of OTP %s blocks on %s: %d\0A\00"
@.str.7 = [8 x i8] c"factory\00"
@.str.8 = [5 x i8] c"user\00"
@OTPGETREGIONINFO = global i32 0
@.str.9 = [51 x i8] c"block %2d: offset = 0x%04x size = %2d bytes %s\0A\00"
@.str.10 = [9 x i8] c"[locked]\00"
@.str.11 = [11 x i8] c"[unlocked]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %27, label %15
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21, %2
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @EINVAL
store i32 %30, i32* %3
br label %143
31: ; preds = %21, %15
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @perror(i8* %42)
%44 = load i32, i32* @errno
store i32 %44, i32* %3
br label %143
45: ; preds = %31
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 102
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = load i32, i32* @MTD_OTP_FACTORY
br label %57
55: ; preds = %45
%56 = load i32, i32* @MTD_OTP_USER
br label %57
57: ; preds = %55, %53
%58 = phi i32 [ %54, %53 ], [ %56, %55 ]
store i32 %58, i32* %7
%59 = load i32, i32* %6
%60 = load i32, i32* @OTPSELECT
%61 = call i32 (i32, i32, ...) @ioctl(i32 %59, i32 %60, i32* %7)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %57
%65 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* @errno
store i32 %66, i32* %3
br label %143
67: ; preds = %57
%68 = load i32, i32* %6
%69 = load i32, i32* @OTPGETREGIONCOUNT
%70 = call i32 (i32, i32, ...) @ioctl(i32 %68, i32 %69, i32* %7)
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%75 = load i32, i32* @errno
store i32 %75, i32* %3
br label %143
76: ; preds = %67
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 102
%84 = zext i1 %83 to i64
%85 = select i1 %83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0)
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 2
%88 = load i8*, i8** %87
%89 = load i32, i32* %7
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %85, i8* %88, i32 %89)
%91 = load i32, i32* %7
%92 = icmp sgt i32 %91, 0
br i1 %92, label %93, label %140
93: ; preds = %76
%94 = load i32, i32* %7
%95 = zext i32 %94 to i64
%96 = call i8* @llvm.stacksave()
store i8* %96, i8** %10
%97 = alloca %struct.otp_info, i64 %95
store i64 %95, i64* %11
%98 = load i32, i32* %6
%99 = load i32, i32* @OTPGETREGIONINFO
%100 = call i32 (i32, i32, ...) @ioctl(i32 %98, i32 %99, %struct.otp_info* %97)
store i32 %100, i32* %9
%101 = load i32, i32* %9
%102 = icmp slt i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %93
%104 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%105 = load i32, i32* @errno
store i32 %105, i32* %3
store i32 1, i32* %12
br label %136
106: ; preds = %93
store i32 0, i32* %8
br label %107
107: ; preds = %132, %106
%108 = load i32, i32* %8
%109 = load i32, i32* %7
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %135
111: ; preds = %107
%112 = load i32, i32* %8
%113 = load i32, i32* %8
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %97, i64 %114
%116 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %115, i32 0, i32 0
%117 = load i32, i32* %116
%118 = load i32, i32* %8
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %97, i64 %119
%121 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %120, i32 0, i32 1
%122 = load i32, i32* %121
%123 = load i32, i32* %8
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %97, i64 %124
%126 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %125, i32 0, i32 2
%127 = load i64, i64* %126
%128 = icmp ne i64 %127, 0
%129 = zext i1 %128 to i64
%130 = select i1 %128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0)
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0), i32 %112, i32 %117, i32 %122, i8* %130)
br label %132
132: ; preds = %111
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
br label %107
135: ; preds = %107
store i32 0, i32* %12
br label %136
136: ; preds = %135, %103
%137 = load i8*, i8** %10
%138 = load i32, i32* %12
switch i32 %138, label %145 [
i32 0, label %139
i32 1, label %143
]
139: ; preds = %136
br label %140
140: ; preds = %139, %76
%141 = load i32, i32* %6
%142 = call i32 @close(i32 %141)
store i32 0, i32* %3
br label %143
143: ; preds = %140, %136, %73, %64, %39, %27
%144 = load i32, i32* %3
ret i32 %144
145: ; preds = %136
unreachable
}

LLVM IR (-O2):
%struct.otp_info = type { i32, i32, i64 }
@.str = [3 x i8] c"-f\00"
@.str.1 = [3 x i8] c"-u\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Usage: %s [ -f | -u ] <device>\0A\00"
@.str.3 = [15 x i8] c"flash_otp_info\00"
@EINVAL = global i32 0
@O_RDONLY = global i32 0
@errno = global i32 0
@MTD_OTP_FACTORY = global i32 0
@MTD_OTP_USER = global i32 0
@OTPSELECT = global i32 0
@.str.4 = [10 x i8] c"OTPSELECT\00"
@OTPGETREGIONCOUNT = global i32 0
@.str.5 = [18 x i8] c"OTPGETREGIONCOUNT\00"
@.str.6 = [35 x i8] c"Number of OTP %s blocks on %s: %d\0A\00"
@.str.7 = [8 x i8] c"factory\00"
@.str.8 = [5 x i8] c"user\00"
@OTPGETREGIONINFO = global i32 0
@.str.9 = [51 x i8] c"block %2d: offset = 0x%04x size = %2d bytes %s\0A\00"
@.str.10 = [9 x i8] c"[locked]\00"
@.str.11 = [11 x i8] c"[unlocked]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11, %2
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* @EINVAL
br label %93
19: ; preds = %11, %6
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = tail call i32 @open(i8* %21, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i8*, i8** %20
%27 = tail call i32 @perror(i8* %26)
%28 = load i32, i32* @errno
br label %93
29: ; preds = %19
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 102
%34 = load i32, i32* @MTD_OTP_FACTORY
%35 = load i32, i32* @MTD_OTP_USER
%36 = select i1 %33, i32 %34, i32 %35
store i32 %36, i32* %3
%37 = load i32, i32* @OTPSELECT
%38 = call i32 (i32, i32, ...) @ioctl(i32 %23, i32 %37, i32* %3)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %29
%41 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32, i32* @errno
br label %93
43: ; preds = %29
%44 = load i32, i32* @OTPGETREGIONCOUNT
%45 = call i32 (i32, i32, ...) @ioctl(i32 %23, i32 %44, i32* %3)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @errno
br label %93
50: ; preds = %43
%51 = load i8*, i8** %7
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 102
%55 = select i1 %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0)
%56 = load i8*, i8** %20
%57 = load i32, i32* %3
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %55, i8* %56, i32 %57)
%59 = load i32, i32* %3
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %91
61: ; preds = %50
%62 = zext i32 %59 to i64
%63 = call i8* @llvm.stacksave()
%64 = alloca %struct.otp_info, i64 %62
%65 = load i32, i32* @OTPGETREGIONINFO
%66 = call i32 (i32, i32, ...) @ioctl(i32 %23, i32 %65, %struct.otp_info* %64)
%67 = icmp slt i32 %66, 0
br i1 %67, label %71, label %68
68: ; preds = %61
%69 = load i32, i32* %3
%70 = icmp sgt i32 %69, 0
br i1 %70, label %74, label %90
71: ; preds = %61
%72 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* @errno
br label %93
74: ; preds = %68, %74
%75 = phi i64 [ %86, %74 ], [ 0, %68 ]
%76 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %64, i64 %75, i32 0
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %64, i64 %75, i32 1
%79 = load i32, i32* %78
%80 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %64, i64 %75, i32 2
%81 = load i64, i64* %80
%82 = icmp eq i64 %81, 0
%83 = select i1 %82, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0)
%84 = trunc i64 %75 to i32
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0), i32 %84, i32 %77, i32 %79, i8* %83)
%86 = add nuw nsw i64 %75, 1
%87 = load i32, i32* %3
%88 = sext i32 %87 to i64
%89 = icmp slt i64 %86, %88
br i1 %89, label %74, label %90
90: ; preds = %74, %68
br label %91
91: ; preds = %90, %50
%92 = call i32 @close(i32 %23)
br label %93
93: ; preds = %71, %91, %47, %40, %25, %15
%94 = phi i32 [ %18, %15 ], [ %28, %25 ], [ %42, %40 ], [ %49, %47 ], [ 0, %91 ], [ %73, %71 ]
ret i32 %94
}