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

/* Variables and functions */
scalar_t__ SDCheck();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getSdCID(char *cid) {
  cid[0] = '\0';
  if (SDCheck() == 0) {
    FILE *fp;
    fp = fopen("/sys/block/mmcblk0/device/cid", "r");
    if (fp != NULL) {
      if (fgets(cid, 33, fp) == NULL) {
        return -1;
      }
      fclose(fp);
      return (cid[0] == '\0');
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<getSdCID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x0,%al
call   1040 <SDCheck@plt>
cmp    $0x0,%rax
jne    11d6 <getSdCID+0x96>
lea    0xe95(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <getSdCID+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x21,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11ae <getSdCID+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <getSdCID+0x9d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11dd <getSdCID+0x9d>
jmp    11d6 <getSdCID+0x96>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSdCID>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
movb   $0x0,(%rdi)
xor    %eax,%eax
call   1040 <SDCheck@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    119c <getSdCID+0x5c>
lea    0xe9e(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <getSdCID+0x5c>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x21,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     119c <getSdCID+0x5c>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
cmpb   $0x0,(%rbx)
sete   %bpl
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/block/mmcblk0/device/cid\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @getSdCID(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
store i8 0, i8* %6
%7 = call i64 (...) @SDCheck()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %28
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32*, i32** %4
%16 = call i32* @fgets(i8* %14, i32 33, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %2
br label %30
19: ; preds = %13
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
store i32 %27, i32* %2
br label %30
28: ; preds = %9
br label %29
29: ; preds = %28, %1
store i32 -1, i32* %2
br label %30
30: ; preds = %29, %19, %18
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/block/mmcblk0/device/cid\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @getSdCID(i8* %0) {
store i8 0, i8* %0
%2 = tail call i64 (...) @SDCheck()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = tail call i32* @fgets(i8* %0, i32 33, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = tail call i32 @fclose(i32* %5)
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %7, %10, %1, %4
%16 = phi i32 [ -1, %4 ], [ -1, %1 ], [ -1, %7 ], [ %14, %10 ]
ret i32 %16
}