#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 */
scalar_t__ get_Product_mac(unsigned char *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
unsigned char swim_chang(unsigned char);
scalar_t__ write_buffer_otp(int, unsigned char *, int);
int encrypt_write() {
  unsigned char mac[20];
  unsigned char buff[32];
  memset(mac, 0, 20);
  if (get_Product_mac(mac) < 0) {
    printf("get product error\n");
    return -1;
  }
  buff[0] = swim_chang(mac[0]);
  buff[1] = swim_chang(mac[1]);
  buff[4] = swim_chang(mac[2]);
  buff[5] = swim_chang(mac[3]);
  buff[8] = swim_chang(mac[4]);
  buff[9] = swim_chang(mac[5]);
  buff[12] = swim_chang(mac[6]);
  buff[13] = swim_chang(mac[7]);
  buff[16] = swim_chang(mac[8]);
  buff[17] = swim_chang(mac[9]);
  buff[20] = swim_chang(mac[10]);
  buff[21] = swim_chang(mac[11]);
  if (write_buffer_otp(0xb8114030, buff, 32) < 0) {
    printf("write otp error\n");
    return -1;
  }
  printf("write otp ok\n");
  return 0;
}


x86 assembly (clang, -O0):
<encrypt_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
call   1070 <get_Product_mac@plt>
cmp    $0x0,%rax
jge    1193 <encrypt_write+0x43>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <encrypt_write+0x11b>
movzbl -0x20(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x40(%rbp)
movzbl -0x1f(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x3f(%rbp)
movzbl -0x1e(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x3c(%rbp)
movzbl -0x1d(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x3b(%rbp)
movzbl -0x1c(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x38(%rbp)
movzbl -0x1b(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x37(%rbp)
movzbl -0x1a(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x34(%rbp)
movzbl -0x19(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x33(%rbp)
movzbl -0x18(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x30(%rbp)
movzbl -0x17(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x2f(%rbp)
movzbl -0x16(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x2c(%rbp)
movzbl -0x15(%rbp),%edi
call   1060 <swim_chang@plt>
mov    %al,-0x2b(%rbp)
lea    -0x40(%rbp),%rsi
mov    $0xb8114030,%edi
mov    $0x20,%edx
call   1050 <write_buffer_otp@plt>
cmp    $0x0,%rax
jge    1258 <encrypt_write+0x108>
lea    0xdcc(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <encrypt_write+0x11b>
lea    0xdc5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encrypt_write>:
push   %rbx
sub    $0x40,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1070 <get_Product_mac@plt>
test   %rax,%rax
js     1251 <encrypt_write+0x101>
movzbl (%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x20(%rsp)
movzbl 0x1(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x21(%rsp)
movzbl 0x2(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x24(%rsp)
movzbl 0x3(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x25(%rsp)
movzbl 0x4(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x28(%rsp)
movzbl 0x5(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x29(%rsp)
movzbl 0x6(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x2c(%rsp)
movzbl 0x7(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x2d(%rsp)
movzbl 0x8(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x30(%rsp)
movzbl 0x9(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x31(%rsp)
movzbl 0xa(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x34(%rsp)
movzbl 0xb(%rsp),%edi
call   1060 <swim_chang@plt>
mov    %al,0x35(%rsp)
lea    0x20(%rsp),%rsi
mov    $0xb8114030,%edi
mov    $0x20,%edx
call   1050 <write_buffer_otp@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xdcd(%rip),%rax
lea    0xdb9(%rip),%rdi
cmovs  %rax,%rdi
sar    $0x3f,%rbx
jmp    125d <encrypt_write+0x10d>
mov    $0xffffffff,%ebx
lea    0xdc0(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"get product error\0A\00"
@.str.1 = [17 x i8] c"write otp error\0A\00"
@.str.2 = [14 x i8] c"write otp ok\0A\00"
define i32 @encrypt_write() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 20)
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%7 = call i64 @get_Product_mac(i8* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
11: ; preds = %0
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %12
%14 = call zeroext i8 @swim_chang(i8 zeroext %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
store i8 %14, i8* %15
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 1
%17 = load i8, i8* %16
%18 = call zeroext i8 @swim_chang(i8 zeroext %17)
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 1
store i8 %18, i8* %19
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 2
%21 = load i8, i8* %20
%22 = call zeroext i8 @swim_chang(i8 zeroext %21)
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 4
store i8 %22, i8* %23
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 3
%25 = load i8, i8* %24
%26 = call zeroext i8 @swim_chang(i8 zeroext %25)
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 5
store i8 %26, i8* %27
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 4
%29 = load i8, i8* %28
%30 = call zeroext i8 @swim_chang(i8 zeroext %29)
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 8
store i8 %30, i8* %31
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 5
%33 = load i8, i8* %32
%34 = call zeroext i8 @swim_chang(i8 zeroext %33)
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 9
store i8 %34, i8* %35
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 6
%37 = load i8, i8* %36
%38 = call zeroext i8 @swim_chang(i8 zeroext %37)
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 12
store i8 %38, i8* %39
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 7
%41 = load i8, i8* %40
%42 = call zeroext i8 @swim_chang(i8 zeroext %41)
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 13
store i8 %42, i8* %43
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 8
%45 = load i8, i8* %44
%46 = call zeroext i8 @swim_chang(i8 zeroext %45)
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 16
store i8 %46, i8* %47
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 9
%49 = load i8, i8* %48
%50 = call zeroext i8 @swim_chang(i8 zeroext %49)
%51 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 17
store i8 %50, i8* %51
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 10
%53 = load i8, i8* %52
%54 = call zeroext i8 @swim_chang(i8 zeroext %53)
%55 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 20
store i8 %54, i8* %55
%56 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 11
%57 = load i8, i8* %56
%58 = call zeroext i8 @swim_chang(i8 zeroext %57)
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 21
store i8 %58, i8* %59
%60 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%61 = call i64 @write_buffer_otp(i32 -1206829008, i8* %60, i32 32)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %11
%64 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %67
65: ; preds = %11
%66 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %67
67: ; preds = %65, %63, %9
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
@str = [13 x i8] c"write otp ok\00"
@str.3 = [16 x i8] c"write otp error\00"
@str.4 = [18 x i8] c"get product error\00"
define i32 @encrypt_write() {
%1 = alloca [20 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %3, i32 0, i32 20)
%6 = call i64 @get_Product_mac(i8* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %60, label %8
8: ; preds = %0
%9 = load i8, i8* %3
%10 = call zeroext i8 @swim_chang(i8 zeroext %9)
store i8 %10, i8* %4
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 1
%12 = load i8, i8* %11
%13 = call zeroext i8 @swim_chang(i8 zeroext %12)
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 1
store i8 %13, i8* %14
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 2
%16 = load i8, i8* %15
%17 = call zeroext i8 @swim_chang(i8 zeroext %16)
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 4
store i8 %17, i8* %18
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 3
%20 = load i8, i8* %19
%21 = call zeroext i8 @swim_chang(i8 zeroext %20)
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 5
store i8 %21, i8* %22
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 4
%24 = load i8, i8* %23
%25 = call zeroext i8 @swim_chang(i8 zeroext %24)
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 8
store i8 %25, i8* %26
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 5
%28 = load i8, i8* %27
%29 = call zeroext i8 @swim_chang(i8 zeroext %28)
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 9
store i8 %29, i8* %30
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 6
%32 = load i8, i8* %31
%33 = call zeroext i8 @swim_chang(i8 zeroext %32)
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 12
store i8 %33, i8* %34
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 7
%36 = load i8, i8* %35
%37 = call zeroext i8 @swim_chang(i8 zeroext %36)
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 13
store i8 %37, i8* %38
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 8
%40 = load i8, i8* %39
%41 = call zeroext i8 @swim_chang(i8 zeroext %40)
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 16
store i8 %41, i8* %42
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 9
%44 = load i8, i8* %43
%45 = call zeroext i8 @swim_chang(i8 zeroext %44)
%46 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 17
store i8 %45, i8* %46
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 10
%48 = load i8, i8* %47
%49 = call zeroext i8 @swim_chang(i8 zeroext %48)
%50 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 20
store i8 %49, i8* %50
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 11
%52 = load i8, i8* %51
%53 = call zeroext i8 @swim_chang(i8 zeroext %52)
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 21
store i8 %53, i8* %54
%55 = call i64 @write_buffer_otp(i32 -1206829008, i8* %4, i32 32)
%56 = icmp slt i64 %55, 0
%57 = select i1 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0)
%58 = ashr i64 %55, 63
%59 = trunc i64 %58 to i32
br label %60
60: ; preds = %8, %0
%61 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0), %0 ], [ %57, %8 ]
%62 = phi i32 [ -1, %0 ], [ %59, %8 ]
%63 = call i32 @puts(i8* dereferenceable(1) %61)
ret i32 %62
}