#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 cid_backdoor(int);
int /*<<< orphan*/ close(int);
unsigned char crc7(unsigned char *, int);
int htonl(int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ parse_serial(char const *);
int /*<<< orphan*/ printf(char *, ...);
int program_cid(int, unsigned char *);
int /*<<< orphan*/ show_cid(unsigned char *);
int sscanf(char const *, char *, unsigned char *);
int strlen(char const *);
void main(int argc, const char **argv) {
  int fd, ret, i, len;
  unsigned char cid[16] = {0};
  if (argc != 3 && argc != 4) {
    printf("Usage: ./evoplus_cid <device> <cid> [serial]\n");
    printf("device - sd card block device e.g. /dev/block/mmcblk1\n");
    printf("cid - new cid, must be in hex (without 0x prefix)\n");
    printf("  it can be 32 chars with checksum or 30 chars without, it will\n");
    printf(
        "  be updated with new serial number if supplied, the checksum is\n");
    printf("  (re)calculated if not supplied or new serial applied\n");
    printf("serial - optional, can be hex (0x prefixed) or decimal\n");
    printf("  and will be applied to the supplied cid before writing\n");
    printf("\n");
    printf("Warning: use at own risk!\n");
    return;
  }
  len = strlen(argv[2]);
  if (len != 30 && len != 32) {
    printf("CID should be 30 or 32 chars long!\n");
    return;
  }
  for (i = 0; i < (len / 2); i++) {
    ret = sscanf(&argv[2][i * 2], "%2hhx", &cid[i]);
    if (!ret) {
      printf("CID should be hex (without 0x prefix)!\n");
      return;
    }
  }
  if (argc == 4) {
    *((int *)&cid[9]) = htonl(parse_serial(argv[3]));
  }
  if (len != 32 || argc == 4) {
    cid[15] = crc7(cid, 15);
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    printf("Unable to open device %s\n", argv[1]);
    return;
  }
  ret = cid_backdoor(fd);
  if (!ret) {
    printf("Writing new CID: ");
    show_cid(cid);
    ret = program_cid(fd, cid);
    if (!ret) {
      printf("Success! Remove and reinsert SD card to check new CID.\n");
    }
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
cmpl   $0x3,-0x4(%rbp)
je     1284 <main+0xc4>
cmpl   $0x4,-0x4(%rbp)
je     1284 <main+0xc4>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xf05(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xf2f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xfc6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xf4d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1421 <main+0x261>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1e,-0x20(%rbp)
je     12bb <main+0xfb>
cmpl   $0x20,-0x20(%rbp)
je     12bb <main+0xfb>
lea    0xf31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1421 <main+0x261>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    133d <main+0x17d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x1c(%rbp),%rax
lea    -0x30(%rbp),%rdx
add    %rax,%rdx
lea    0xeff(%rip),%rsi
call   10c0 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    132a <main+0x16a>
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1421 <main+0x261>
jmp    132f <main+0x16f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c2 <main+0x102>
cmpl   $0x4,-0x4(%rbp)
jne    135e <main+0x19e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <parse_serial@plt>
mov    %eax,%edi
call   1080 <htonl@plt>
mov    %eax,-0x27(%rbp)
cmpl   $0x20,-0x20(%rbp)
jne    1372 <main+0x1b2>
cmpl   $0x4,-0x4(%rbp)
jne    1383 <main+0x1c3>
lea    -0x30(%rbp),%rdi
mov    $0xf,%esi
call   1050 <crc7@plt>
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c56(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13c1 <main+0x201>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1421 <main+0x261>
mov    -0x14(%rbp),%edi
call   1030 <cid_backdoor@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1419 <main+0x259>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x30(%rbp),%rdi
call   10e0 <show_cid@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <program_cid@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1414 <main+0x254>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1419 <main+0x259>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r14d
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    -0x5(%r14),%eax
cmp    $0xfffffffd,%eax
ja     1268 <main+0x98>
lea    0xeba(%rip),%rdi
call   1050 <puts@plt>
lea    0xedb(%rip),%rdi
call   1050 <puts@plt>
lea    0xf05(%rip),%rdi
call   1050 <puts@plt>
lea    0xf2b(%rip),%rdi
call   1050 <puts@plt>
lea    0xf5f(%rip),%rdi
call   1050 <puts@plt>
lea    0xf94(%rip),%rdi
call   1050 <puts@plt>
lea    0xfbf(%rip),%rdi
call   1050 <puts@plt>
lea    0xfea(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0x100d(%rip),%rdi
jmp    12f8 <main+0x128>
mov    %rsi,%r13
mov    0x10(%rsi),%rdi
call   1080 <strlen@plt>
cmp    $0x1e,%eax
je     127e <main+0xae>
cmp    $0x20,%eax
jne    12f1 <main+0x121>
mov    %eax,0xc(%rsp)
mov    %eax,%ebx
shr    %ebx
and    $0x7f,%ebx
lea    0x10(%rsp),%rbp
xor    %r15d,%r15d
lea    0xd68(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    0x10(%r13),%rdi
add    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   10d0 <sscanf@plt>
test   %eax,%eax
je     12e0 <main+0x110>
add    $0x2,%r15
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
jne    12a0 <main+0xd0>
cmp    $0x4,%r14d
jne    130b <main+0x13b>
mov    0x18(%r13),%rdi
call   10c0 <parse_serial@plt>
mov    %eax,%edi
call   10a0 <htonl@plt>
mov    %eax,0x19(%rsp)
jmp    1312 <main+0x142>
lea    0xd82(%rip),%rdi
call   1050 <puts@plt>
jmp    1398 <main+0x1c8>
lea    0xd98(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <puts@plt>
cmpl   $0x20,0xc(%rsp)
je     1325 <main+0x155>
lea    0x10(%rsp),%rdi
mov    $0xf,%esi
call   1070 <crc7@plt>
mov    %al,0x1f(%rsp)
mov    0x8(%r13),%rdi
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
test   %eax,%eax
js     1386 <main+0x1b6>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <cid_backdoor@plt>
test   %eax,%eax
jne    137d <main+0x1ad>
lea    0xcd1(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10f0 <show_cid@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <program_cid@plt>
test   %eax,%eax
jne    137d <main+0x1ad>
lea    0xcba(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
jmp    1398 <main+0x1c8>
mov    0x8(%r13),%rsi
lea    0xc75(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Usage: ./evoplus_cid <device> <cid> [serial]\0A\00"
@.str.1 = [55 x i8] c"device - sd card block device e.g. /dev/block/mmcblk1\0A\00"
@.str.2 = [51 x i8] c"cid - new cid, must be in hex (without 0x prefix)\0A\00"
@.str.3 = [65 x i8] c" it can be 32 chars with checksum or 30 chars without, it will\0A\00"
@.str.4 = [66 x i8] c" be updated with new serial number if supplied, the checksum is\0A\00"
@.str.5 = [56 x i8] c" (re)calculated if not supplied or new serial applied\0A\00"
@.str.6 = [56 x i8] c"serial - optional, can be hex (0x prefixed) or decimal\0A\00"
@.str.7 = [58 x i8] c" and will be applied to the supplied cid before writing\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [27 x i8] c"Warning: use at own risk!\0A\00"
@.str.10 = [36 x i8] c"CID should be 30 or 32 chars long!\0A\00"
@.str.11 = [6 x i8] c"%2hhx\00"
@.str.12 = [40 x i8] c"CID should be hex (without 0x prefix)!\0A\00"
@O_RDWR = global i32 0
@.str.13 = [26 x i8] c"Unable to open device %s\0A\00"
@.str.14 = [18 x i8] c"Writing new CID: \00"
@.str.15 = [56 x i8] c"Success! Remove and reinsert SD card to check new CID.\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = bitcast [16 x i8]* %9 to i8*
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.7, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
br label %119
27: ; preds = %13, %2
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp ne i32 %32, 30
br i1 %33, label %34, label %39
34: ; preds = %27
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 32
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0))
br label %119
39: ; preds = %34, %27
store i32 0, i32* %7
br label %40
40: ; preds = %62, %39
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = sdiv i32 %42, 2
%44 = icmp slt i32 %41, %43
br i1 %44, label %45, label %65
45: ; preds = %40
%46 = load i8**, i8*** %4
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i32, i32* %7
%50 = mul nsw i32 %49, 2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 %54
%56 = call i32 @sscanf(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* %55)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp ne i32 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %45
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %119
61: ; preds = %45
br label %62
62: ; preds = %61
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
br label %40
65: ; preds = %40
%66 = load i32, i32* %3
%67 = icmp eq i32 %66, 4
br i1 %67, label %68, label %76
68: ; preds = %65
%69 = load i8**, i8*** %4
%70 = getelementptr inbounds i8*, i8** %69, i64 3
%71 = load i8*, i8** %70
%72 = call i32 @parse_serial(i8* %71)
%73 = call i32 @htonl(i32 %72)
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 9
%75 = bitcast i8* %74 to i32*
store i32 %73, i32* %75
br label %76
76: ; preds = %68, %65
%77 = load i32, i32* %8
%78 = icmp ne i32 %77, 32
br i1 %78, label %82, label %79
79: ; preds = %76
%80 = load i32, i32* %3
%81 = icmp eq i32 %80, 4
br i1 %81, label %82, label %86
82: ; preds = %79, %76
%83 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%84 = call zeroext i8 @crc7(i8* %83, i32 15)
%85 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 15
store i8 %84, i8* %85
br label %86
86: ; preds = %82, %79
%87 = load i8**, i8*** %4
%88 = getelementptr inbounds i8*, i8** %87, i64 1
%89 = load i8*, i8** %88
%90 = load i32, i32* @O_RDWR
%91 = call i32 @open(i8* %89, i32 %90)
store i32 %91, i32* %5
%92 = load i32, i32* %5
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %86
%95 = load i8**, i8*** %4
%96 = getelementptr inbounds i8*, i8** %95, i64 1
%97 = load i8*, i8** %96
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %97)
br label %119
99: ; preds = %86
%100 = load i32, i32* %5
%101 = call i32 @cid_backdoor(i32 %100)
store i32 %101, i32* %6
%102 = load i32, i32* %6
%103 = icmp ne i32 %102, 0
br i1 %103, label %116, label %104
104: ; preds = %99
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
%106 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%107 = call i32 @show_cid(i8* %106)
%108 = load i32, i32* %5
%109 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%110 = call i32 @program_cid(i32 %108, i8* %109)
store i32 %110, i32* %6
%111 = load i32, i32* %6
%112 = icmp ne i32 %111, 0
br i1 %112, label %115, label %113
113: ; preds = %104
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.15, i64 0, i64 0))
br label %115
115: ; preds = %113, %104
br label %116
116: ; preds = %115, %99
%117 = load i32, i32* %5
%118 = call i32 @close(i32 %117)
br label %119
119: ; preds = %116, %94, %59, %37, %16
ret void
}

LLVM IR (-O2):
@.str.11 = [6 x i8] c"%2hhx\00"
@O_RDWR = global i32 0
@.str.13 = [26 x i8] c"Unable to open device %s\0A\00"
@.str.14 = [18 x i8] c"Writing new CID: \00"
@str = [55 x i8] c"Success! Remove and reinsert SD card to check new CID.\00"
@str.16 = [39 x i8] c"CID should be hex (without 0x prefix)!\00"
@str.17 = [35 x i8] c"CID should be 30 or 32 chars long!\00"
@str.18 = [45 x i8] c"Usage: ./evoplus_cid <device> <cid> [serial]\00"
@str.19 = [54 x i8] c"device - sd card block device e.g. /dev/block/mmcblk1\00"
@str.20 = [50 x i8] c"cid - new cid, must be in hex (without 0x prefix)\00"
@str.21 = [64 x i8] c" it can be 32 chars with checksum or 30 chars without, it will\00"
@str.22 = [65 x i8] c" be updated with new serial number if supplied, the checksum is\00"
@str.23 = [55 x i8] c" (re)calculated if not supplied or new serial applied\00"
@str.24 = [55 x i8] c"serial - optional, can be hex (0x prefixed) or decimal\00"
@str.25 = [57 x i8] c" and will be applied to the supplied cid before writing\00"
@str.26 = [26 x i8] c"Warning: use at own risk!\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = add i32 %0, -5
%6 = icmp ult i32 %5, -2
br i1 %6, label %7, label %18
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.18, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.19, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.20, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.21, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.22, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.23, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.24, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.25, i64 0, i64 0))
%16 = tail call i32 @putchar(i32 10)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.26, i64 0, i64 0))
br label %76
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @strlen(i8* %20)
%22 = icmp eq i32 %21, 32
switch i32 %21, label %23 [
i32 32, label %25
i32 30, label %25
]
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.17, i64 0, i64 0))
br label %76
25: ; preds = %18, %18
%26 = lshr i32 %21, 1
%27 = and i32 %26, 127
%28 = zext i32 %27 to i64
br label %31
29: ; preds = %31
%30 = icmp eq i64 %39, %28
br i1 %30, label %42, label %31
31: ; preds = %25, %29
%32 = phi i64 [ 0, %25 ], [ %39, %29 ]
%33 = load i8*, i8** %19
%34 = shl nuw nsw i64 %32, 1
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %32
%37 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* %36)
%38 = icmp eq i32 %37, 0
%39 = add nuw nsw i64 %32, 1
br i1 %38, label %40, label %29
40: ; preds = %31
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.16, i64 0, i64 0))
br label %76
42: ; preds = %29
%43 = icmp eq i32 %0, 4
br i1 %43, label %44, label %51
44: ; preds = %42
%45 = getelementptr inbounds i8*, i8** %1, i64 3
%46 = load i8*, i8** %45
%47 = call i32 @parse_serial(i8* %46)
%48 = call i32 @htonl(i32 %47)
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 9
%50 = bitcast i8* %49 to i32*
store i32 %48, i32* %50
br label %52
51: ; preds = %42
br i1 %22, label %55, label %52
52: ; preds = %44, %51
%53 = call zeroext i8 @crc7(i8* %4, i32 15)
%54 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 15
store i8 %53, i8* %54
br label %55
55: ; preds = %51, %52
%56 = getelementptr inbounds i8*, i8** %1, i64 1
%57 = load i8*, i8** %56
%58 = load i32, i32* @O_RDWR
%59 = call i32 @open(i8* %57, i32 %58)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = load i8*, i8** %56
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i8* %62)
br label %76
64: ; preds = %55
%65 = call i32 @cid_backdoor(i32 %59)
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %74
67: ; preds = %64
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0))
%69 = call i32 @show_cid(i8* %4)
%70 = call i32 @program_cid(i32 %59, i8* %4)
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %67
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %74
74: ; preds = %67, %72, %64
%75 = call i32 @close(i32 %59)
br label %76
76: ; preds = %74, %61, %40, %23, %7
ret void
}