#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", argv[0]);
    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
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe23(%rip),%rsi
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    0xd89(%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    0xd52(%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    0xd66(%rip),%rsi
lea    0xd57(%rip),%rax
cmp    $0x66,%ecx
cmove  %rax,%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x18(%rbp),%ecx
lea    0xd1b(%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    0xcaf(%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    0xcbf(%rip),%r8
lea    0xcaf(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%r8
lea    0xc6d(%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
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11b3 <main+0x43>
mov    0x8(%rbx),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d9 <main+0x69>
mov    0x8(%rbx),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d9 <main+0x69>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe40(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%ebx
jmp    1333 <main+0x1c3>
mov    0x10(%rbx),%rdi
mov    0x2dfc(%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    1209 <main+0x99>
mov    0x2df1(%rip),%rax
jmp    1210 <main+0xa0>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2db4(%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    0x2d75(%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    0xdff(%rip),%rax
lea    0xe00(%rip),%rsi
cmove  %rax,%rsi
mov    -0x2c(%rbp),%ecx
lea    0xdc7(%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    0x2d22(%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    0xdd8(%rip),%r14
lea    0xdc8(%rip),%r15
lea    0xd8e(%rip),%r12
xor    %ebx,%ebx
cs 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    0xcd5(%rip),%rdi
jmp    135a <main+0x1ea>
lea    0xcd6(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%ebx
jmp    1333 <main+0x1c3>
lea    0xcbf(%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"
@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.3 = [10 x i8] c"OTPSELECT\00"
@OTPGETREGIONCOUNT = global i32 0
@.str.4 = [18 x i8] c"OTPGETREGIONCOUNT\00"
@.str.5 = [35 x i8] c"Number of OTP %s blocks on %s: %d\0A\00"
@.str.6 = [8 x i8] c"factory\00"
@.str.7 = [5 x i8] c"user\00"
@OTPGETREGIONINFO = global i32 0
@.str.8 = [51 x i8] c"block %2d: offset = 0x%04x size = %2d bytes %s\0A\00"
@.str.9 = [9 x i8] c"[locked]\00"
@.str.10 = [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 %34
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 %34
27: ; preds = %21, %2
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EINVAL
store i32 %33, i32* %3
br label %146
34: ; preds = %21, %15
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %34
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @perror(i8* %45)
%47 = load i32, i32* @errno
store i32 %47, i32* %3
br label %146
48: ; preds = %34
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = getelementptr inbounds i8, i8* %51, i64 1
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 102
br i1 %55, label %56, label %58
56: ; preds = %48
%57 = load i32, i32* @MTD_OTP_FACTORY
br label %60
58: ; preds = %48
%59 = load i32, i32* @MTD_OTP_USER
br label %60
60: ; preds = %58, %56
%61 = phi i32 [ %57, %56 ], [ %59, %58 ]
store i32 %61, i32* %7
%62 = load i32, i32* %6
%63 = load i32, i32* @OTPSELECT
%64 = call i32 (i32, i32, ...) @ioctl(i32 %62, i32 %63, i32* %7)
store i32 %64, i32* %9
%65 = load i32, i32* %9
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%69 = load i32, i32* @errno
store i32 %69, i32* %3
br label %146
70: ; preds = %60
%71 = load i32, i32* %6
%72 = load i32, i32* @OTPGETREGIONCOUNT
%73 = call i32 (i32, i32, ...) @ioctl(i32 %71, i32 %72, i32* %7)
store i32 %73, i32* %9
%74 = load i32, i32* %9
%75 = icmp slt i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %70
%77 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* @errno
store i32 %78, i32* %3
br label %146
79: ; preds = %70
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i8*, i8** %81
%83 = getelementptr inbounds i8, i8* %82, i64 1
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp eq i32 %85, 102
%87 = zext i1 %86 to i64
%88 = select i1 %86, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 2
%91 = load i8*, i8** %90
%92 = load i32, i32* %7
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %88, i8* %91, i32 %92)
%94 = load i32, i32* %7
%95 = icmp sgt i32 %94, 0
br i1 %95, label %96, label %143
96: ; preds = %79
%97 = load i32, i32* %7
%98 = zext i32 %97 to i64
%99 = call i8* @llvm.stacksave()
store i8* %99, i8** %10
%100 = alloca %struct.otp_info, i64 %98
store i64 %98, i64* %11
%101 = load i32, i32* %6
%102 = load i32, i32* @OTPGETREGIONINFO
%103 = call i32 (i32, i32, ...) @ioctl(i32 %101, i32 %102, %struct.otp_info* %100)
store i32 %103, i32* %9
%104 = load i32, i32* %9
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %109
106: ; preds = %96
%107 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%108 = load i32, i32* @errno
store i32 %108, i32* %3
store i32 1, i32* %12
br label %139
109: ; preds = %96
store i32 0, i32* %8
br label %110
110: ; preds = %135, %109
%111 = load i32, i32* %8
%112 = load i32, i32* %7
%113 = icmp slt i32 %111, %112
br i1 %113, label %114, label %138
114: ; preds = %110
%115 = load i32, i32* %8
%116 = load i32, i32* %8
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %100, i64 %117
%119 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %118, i32 0, i32 0
%120 = load i32, i32* %119
%121 = load i32, i32* %8
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %100, i64 %122
%124 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %123, i32 0, i32 1
%125 = load i32, i32* %124
%126 = load i32, i32* %8
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %100, i64 %127
%129 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %128, i32 0, i32 2
%130 = load i64, i64* %129
%131 = icmp ne i64 %130, 0
%132 = zext i1 %131 to i64
%133 = select i1 %131, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0)
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i32 %115, i32 %120, i32 %125, i8* %133)
br label %135
135: ; preds = %114
%136 = load i32, i32* %8
%137 = add nsw i32 %136, 1
store i32 %137, i32* %8
br label %110
138: ; preds = %110
store i32 0, i32* %12
br label %139
139: ; preds = %138, %106
%140 = load i8*, i8** %10
%141 = load i32, i32* %12
switch i32 %141, label %148 [
i32 0, label %142
i32 1, label %146
]
142: ; preds = %139
br label %143
143: ; preds = %142, %79
%144 = load i32, i32* %6
%145 = call i32 @close(i32 %144)
store i32 0, i32* %3
br label %146
146: ; preds = %143, %139, %76, %67, %42, %27
%147 = load i32, i32* %3
ret i32 %147
148: ; preds = %139
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"
@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.3 = [10 x i8] c"OTPSELECT\00"
@OTPGETREGIONCOUNT = global i32 0
@.str.4 = [18 x i8] c"OTPGETREGIONCOUNT\00"
@.str.5 = [35 x i8] c"Number of OTP %s blocks on %s: %d\0A\00"
@.str.6 = [8 x i8] c"factory\00"
@.str.7 = [5 x i8] c"user\00"
@OTPGETREGIONINFO = global i32 0
@.str.8 = [51 x i8] c"block %2d: offset = 0x%04x size = %2d bytes %s\0A\00"
@.str.9 = [9 x i8] c"[locked]\00"
@.str.10 = [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 %20, 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 %20, label %15
15: ; preds = %11, %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EINVAL
br label %94
20: ; preds = %11, %6
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = tail call i32 @open(i8* %22, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i8*, i8** %21
%28 = tail call i32 @perror(i8* %27)
%29 = load i32, i32* @errno
br label %94
30: ; preds = %20
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 102
%35 = load i32, i32* @MTD_OTP_FACTORY
%36 = load i32, i32* @MTD_OTP_USER
%37 = select i1 %34, i32 %35, i32 %36
store i32 %37, i32* %3
%38 = load i32, i32* @OTPSELECT
%39 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %38, i32* %3)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %30
%42 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @errno
br label %94
44: ; preds = %30
%45 = load i32, i32* @OTPGETREGIONCOUNT
%46 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %45, i32* %3)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @errno
br label %94
51: ; preds = %44
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = load i8, i8* %53
%55 = icmp eq i8 %54, 102
%56 = select i1 %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%57 = load i8*, i8** %21
%58 = load i32, i32* %3
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %56, i8* %57, i32 %58)
%60 = load i32, i32* %3
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %92
62: ; preds = %51
%63 = zext i32 %60 to i64
%64 = call i8* @llvm.stacksave()
%65 = alloca %struct.otp_info, i64 %63
%66 = load i32, i32* @OTPGETREGIONINFO
%67 = call i32 (i32, i32, ...) @ioctl(i32 %24, i32 %66, %struct.otp_info* %65)
%68 = icmp slt i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %62
%70 = load i32, i32* %3
%71 = icmp sgt i32 %70, 0
br i1 %71, label %75, label %91
72: ; preds = %62
%73 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* @errno
br label %94
75: ; preds = %69, %75
%76 = phi i64 [ %87, %75 ], [ 0, %69 ]
%77 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %65, i64 %76, i32 0
%78 = load i32, i32* %77
%79 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %65, i64 %76, i32 1
%80 = load i32, i32* %79
%81 = getelementptr inbounds %struct.otp_info, %struct.otp_info* %65, i64 %76, i32 2
%82 = load i64, i64* %81
%83 = icmp eq i64 %82, 0
%84 = select i1 %83, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0)
%85 = trunc i64 %76 to i32
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i32 %85, i32 %78, i32 %80, i8* %84)
%87 = add nuw nsw i64 %76, 1
%88 = load i32, i32* %3
%89 = sext i32 %88 to i64
%90 = icmp slt i64 %87, %89
br i1 %90, label %75, label %91
91: ; preds = %75, %69
br label %92
92: ; preds = %91, %51
%93 = call i32 @close(i32 %24)
br label %94
94: ; preds = %72, %92, %48, %41, %26, %15
%95 = phi i32 [ %19, %15 ], [ %29, %26 ], [ %43, %41 ], [ %50, %48 ], [ 0, %92 ], [ %74, %72 ]
ret i32 %95
}