#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*/ mtd_info_t;

/* Variables and functions */
int /*<<< orphan*/ MEMGETINFO;
int O_CLOEXEC;
int O_RDONLY;
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ probe_smart_media(int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int mtd_fd;
  int error;
  mtd_info_t mtd_info;
  if (argc != 2) {
    printf("usage: mtd_probe /dev/mtd[n]\n");
    return 1;
  }
  mtd_fd = open(argv[1], O_RDONLY | O_CLOEXEC);
  if (mtd_fd == -1) {
    perror("open");
    exit(-1);
  }
  error = ioctl(mtd_fd, MEMGETINFO, &mtd_info);
  if (error == -1) {
    perror("ioctl");
    exit(-1);
  }
  probe_smart_media(mtd_fd, &mtd_info);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1225 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    0x2e18(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11da <main+0x7a>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1212 <main+0xb2>
lea    0xe20(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <probe_smart_media@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11b9 <main+0x59>
mov    0x8(%rsi),%rdi
mov    0x2e73(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x70>
mov    %eax,%ebx
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11d9 <main+0x79>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1030 <probe_smart_media@plt>
mov    $0xffffffff,%eax
jmp    11ca <main+0x6a>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe29(%rip),%rdi
jmp    11e0 <main+0x80>
lea    0xe25(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"usage: mtd_probe /dev/mtd[n]\0A\00"
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str.1 = [5 x i8] c"open\00"
@MEMGETINFO = global i32 0
@.str.2 = [6 x i8] c"ioctl\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %38
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = load i32, i32* @O_CLOEXEC
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %16, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %13
%27 = load i32, i32* %6
%28 = load i32, i32* @MEMGETINFO
%29 = call i32 @ioctl(i32 %27, i32 %28, i32* %8)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %26
%36 = load i32, i32* %6
%37 = call i32 @probe_smart_media(i32 %36, i32* %8)
store i32 -1, i32* %3
br label %38
38: ; preds = %35, %11
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str.1 = [5 x i8] c"open\00"
@MEMGETINFO = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@str = [29 x i8] c"usage: mtd_probe /dev/mtd[n]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %28
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_CLOEXEC
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* %10, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %8
%20 = load i32, i32* @MEMGETINFO
%21 = call i32 @ioctl(i32 %14, i32 %20, i32* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %19
%27 = call i32 @probe_smart_media(i32 %14, i32* %3)
br label %28
28: ; preds = %26, %6
%29 = phi i32 [ 1, %6 ], [ -1, %26 ]
ret i32 %29
}