#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 mmc_movi_vendor_cmd(int, int);
int /*<<< orphan*/ printf(char *);
int cid_backdoor(int fd) {
  int ret;
  ret = mmc_movi_vendor_cmd(0xEFAC62EC, fd);
  if (ret) {
    printf("Failed to enter vendor mode. Genuine Samsung Evo Plus?\n");
  } else {
    ret = mmc_movi_vendor_cmd(0xEF50, fd);
    if (ret) {
      printf("Unlock command failed.\n");
    } else {
      ret = mmc_movi_vendor_cmd(0x00DECCEE, fd);
      if (ret) {
        printf("Failed to exit vendor mode.\n");
      }
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<cid_backdoor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
mov    $0xefac62ec,%edi
call   1030 <mmc_movi_vendor_cmd@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1156 <cid_backdoor+0x36>
lea    0xeb4(%rip),%rdi
call   1040 <printf@plt>
jmp    11b1 <cid_backdoor+0x91>
mov    -0x4(%rbp),%esi
mov    $0xef50,%edi
call   1030 <mmc_movi_vendor_cmd@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1181 <cid_backdoor+0x61>
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
jmp    11ac <cid_backdoor+0x8c>
mov    -0x4(%rbp),%esi
mov    $0xdeccee,%edi
call   1030 <mmc_movi_vendor_cmd@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11a7 <cid_backdoor+0x87>
lea    0xeae(%rip),%rdi
call   1040 <printf@plt>
jmp    11ac <cid_backdoor+0x8c>
jmp    11b1 <cid_backdoor+0x91>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cid_backdoor>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xefac62ec,%edi
mov    %ebp,%esi
call   1030 <mmc_movi_vendor_cmd@plt>
test   %eax,%eax
je     1140 <cid_backdoor+0x20>
mov    %eax,%ebx
lea    0xef5(%rip),%rdi
jmp    1174 <cid_backdoor+0x54>
mov    $0xef50,%edi
mov    %ebp,%esi
call   1030 <mmc_movi_vendor_cmd@plt>
test   %eax,%eax
je     115b <cid_backdoor+0x3b>
mov    %eax,%ebx
lea    0xec3(%rip),%rdi
jmp    1174 <cid_backdoor+0x54>
mov    $0xdeccee,%edi
mov    %ebp,%esi
call   1030 <mmc_movi_vendor_cmd@plt>
test   %eax,%eax
je     1182 <cid_backdoor+0x62>
mov    %eax,%ebx
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1179 <cid_backdoor+0x59>

LLVM IR (-O0):
@.str = [56 x i8] c"Failed to enter vendor mode. Genuine Samsung Evo Plus?\0A\00"
@.str.1 = [24 x i8] c"Unlock command failed.\0A\00"
@.str.2 = [29 x i8] c"Failed to exit vendor mode.\0A\00"
define i32 @cid_backdoor(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @mmc_movi_vendor_cmd(i32 -273915156, i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
br label %26
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 @mmc_movi_vendor_cmd(i32 61264, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %25
17: ; preds = %10
%18 = load i32, i32* %2
%19 = call i32 @mmc_movi_vendor_cmd(i32 14601454, i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
br label %25
25: ; preds = %24, %15
br label %26
26: ; preds = %25, %8
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@str = [28 x i8] c"Failed to exit vendor mode.\00"
@str.3 = [23 x i8] c"Unlock command failed.\00"
@str.4 = [55 x i8] c"Failed to enter vendor mode. Genuine Samsung Evo Plus?\00"
define i32 @cid_backdoor(i32 %0) {
%2 = tail call i32 @mmc_movi_vendor_cmd(i32 -273915156, i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i32 @mmc_movi_vendor_cmd(i32 61264, i32 %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @mmc_movi_vendor_cmd(i32 14601454, i32 %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7, %4, %1
%11 = phi i8* [ getelementptr inbounds ([55 x i8], [55 x i8]* @str.4, i64 0, i64 0), %1 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0), %7 ]
%12 = phi i32 [ %2, %1 ], [ %5, %4 ], [ %8, %7 ]
%13 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ 0, %7 ], [ %12, %10 ]
ret i32 %15
}