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

/* Variables and functions */
int /*<<< orphan*/ displayBinary(unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int hexToBin(char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  unsigned char publicKey[100];
  int result;
  if (argc < 2) {
    fprintf(stderr, "Usage : %s [public key]\n", argv[0]);
    return 0;
  }
  result = hexToBin(argv[1], publicKey, sizeof(publicKey));
  if (result == 0) {
    fprintf(stderr, "Invalid public key\n");
    return 0;
  }
  if (publicKey[0] != 0x04) {
    fprintf(stderr, "Invalid public key format\n");
    return 0;
  }
  publicKey[0] = ((publicKey[64] & 1) ? 0x03 : 0x02);
  printf("Compressed public key : ");
  displayBinary(publicKey, 33);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118d <main+0x4d>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1244 <main+0x104>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1060 <hexToBin@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jne    11d9 <main+0x99>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1244 <main+0x104>
movzbl -0x80(%rbp),%eax
cmp    $0x4,%eax
je     1209 <main+0xc9>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1244 <main+0x104>
movzbl -0x40(%rbp),%edx
and    $0x1,%edx
mov    $0x2,%eax
mov    $0x3,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x80(%rbp)
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x21,%esi
call   1050 <displayBinary@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
cmp    $0x1,%edi
jg     1168 <main+0x28>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xea3(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11d9 <main+0x99>
mov    0x8(%rsi),%rdi
mov    %rsp,%rsi
mov    $0x64,%edx
call   1060 <hexToBin@plt>
test   %eax,%eax
je     11ae <main+0x6e>
cmpb   $0x4,(%rsp)
jne    11c0 <main+0x80>
mov    0x40(%rsp),%al
and    $0x1,%al
or     $0x2,%al
mov    %al,(%rsp)
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0x21,%esi
call   1050 <displayBinary@plt>
mov    $0x1,%ebx
jmp    11d9 <main+0x99>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
jmp    11d0 <main+0x90>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Usage : %s [public key]\0A\00"
@.str.1 = [20 x i8] c"Invalid public key\0A\00"
@.str.2 = [27 x i8] c"Invalid public key format\0A\00"
@.str.3 = [25 x i8] c"Compressed public key : \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %48
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%21 = call i32 @hexToBin(i8* %19, i8* %20, i32 100)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %48
27: ; preds = %16
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp ne i32 %30, 4
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %48
35: ; preds = %27
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 64
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = and i32 %38, 1
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 3, i32 2
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
store i8 %43, i8* %44
%45 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%47 = call i32 @displayBinary(i8* %46, i32 33)
store i32 1, i32* %3
br label %48
48: ; preds = %35, %32, %24, %10
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Usage : %s [public key]\0A\00"
@.str.1 = [20 x i8] c"Invalid public key\0A\00"
@.str.2 = [27 x i8] c"Invalid public key format\0A\00"
@.str.3 = [25 x i8] c"Compressed public key : \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %31
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @hexToBin(i8* %12, i8* %4, i32 100)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %31
18: ; preds = %10
%19 = load i8, i8* %4
%20 = icmp eq i8 %19, 4
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %31
24: ; preds = %18
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 64
%26 = load i8, i8* %25
%27 = and i8 %26, 1
%28 = or i8 %27, 2
store i8 %28, i8* %4
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @displayBinary(i8* %4, i32 33)
br label %31
31: ; preds = %24, %21, %15, %6
%32 = phi i32 [ 0, %6 ], [ 0, %15 ], [ 0, %21 ], [ 1, %24 ]
ret i32 %32
}