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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int ioctl(int, int, unsigned long);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main() {
  int status = 0;
  int sd_mmcdevfs;
  sd_mmcdevfs = open("/dev/mem_stkblk0", O_RDWR, 0);
  if (sd_mmcdevfs < 0) {
    printf("No Device");
    close(sd_mmcdevfs);
    return 0;
  }
  if (ioctl(sd_mmcdevfs, 0xAA, (unsigned long)(&status)) == -1) {
    printf("ioctl error\n");
  }
  if (status == 1)
    printf("Memory stick Pro\n");
  else if (status == 2)
    printf("Memory stick\n");
  else
    printf("Unknown device\n");
  close(sd_mmcdevfs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
xor    %edx,%edx
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119a <main+0x5a>
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1216 <main+0xd6>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rdx
mov    $0xaa,%esi
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x80>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11db <main+0x9b>
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
jmp    1207 <main+0xc7>
cmpl   $0x2,-0x8(%rbp)
jne    11f6 <main+0xb6>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
jmp    1202 <main+0xc2>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    1207 <main+0xc7>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11ca <main+0x7a>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    $0xaa,%esi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    119c <main+0x4c>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
lea    0xe80(%rip),%rcx
lea    0xe6a(%rip),%rdx
cmove  %rcx,%rdx
cmp    $0x1,%eax
lea    0xe78(%rip),%rdi
cmovne %rdx,%rdi
call   1030 <puts@plt>
jmp    11d6 <main+0x86>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/dev/mem_stkblk0\00"
@O_RDWR = global i32 0
@.str.1 = [10 x i8] c"No Device\00"
@.str.2 = [13 x i8] c"ioctl error\0A\00"
@.str.3 = [18 x i8] c"Memory stick Pro\0A\00"
@.str.4 = [14 x i8] c"Memory stick\0A\00"
@.str.5 = [16 x i8] c"Unknown device\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4, i32 0)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %3
%11 = call i32 @close(i32 %10)
store i32 0, i32* %1
br label %35
12: ; preds = %0
%13 = load i32, i32* %3
%14 = ptrtoint i32* %2 to i64
%15 = call i32 @ioctl(i32 %13, i32 170, i64 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %32
24: ; preds = %19
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %31
29: ; preds = %24
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
br label %32
32: ; preds = %31, %22
%33 = load i32, i32* %3
%34 = call i32 @close(i32 %33)
store i32 0, i32* %1
br label %35
35: ; preds = %32, %8
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [17 x i8] c"/dev/mem_stkblk0\00"
@O_RDWR = global i32 0
@.str.1 = [10 x i8] c"No Device\00"
@str = [15 x i8] c"Unknown device\00"
@str.6 = [13 x i8] c"Memory stick\00"
@str.7 = [17 x i8] c"Memory stick Pro\00"
@str.8 = [12 x i8] c"ioctl error\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @close(i32 %4)
br label %23
9: ; preds = %0
%10 = ptrtoint i32* %1 to i64
%11 = call i32 @ioctl(i32 %4, i32 170, i64 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* %1
%17 = icmp eq i32 %16, 2
%18 = select i1 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0)
%19 = icmp eq i32 %16, 1
%20 = select i1 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0), i8* %18
%21 = call i32 @puts(i8* dereferenceable(1) %20)
%22 = call i32 @close(i32 %4)
br label %23
23: ; preds = %15, %6
ret i32 0
}