#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ segment_hash(char *, int, char *, size_t, unsigned char *,
                                int, int);
int sscanf(char *, char *, unsigned char *, unsigned char *, unsigned char *,
           unsigned char *);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
int main(int argc, char **argv) {
  unsigned char quad[4];
  char buf[7];
  size_t key_len;
  if (argc != 3) {
    fprintf(stderr, "Usage: cloak <secret> <ip address>\n");
    return 1;
  }
  key_len = strlen(argv[1]);
  if (4 != sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd", quad, quad + 1, quad + 2,
                  quad + 3)) {
    fprintf(stderr, "IP address must be in dotted quad format\n");
    return 2;
  }
  segment_hash(buf, 3, argv[1], key_len, quad, 4, 10);
  printf("%s.", buf);
  segment_hash(buf, 3, argv[1], key_len, quad, 3, 11);
  printf("%s.", buf);
  segment_hash(buf, 6, argv[1], key_len, quad, 2, 13);
  printf("%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1191 <main+0x41>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b8 <main+0x168>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x14(%rbp),%rdx
lea    -0x14(%rbp),%rcx
add    $0x1,%rcx
lea    -0x14(%rbp),%r8
add    $0x2,%r8
lea    -0x14(%rbp),%r9
add    $0x3,%r9
lea    0xe57(%rip),%rsi
call   1070 <sscanf@plt>
mov    %eax,%ecx
mov    $0x4,%eax
cmp    %ecx,%eax
je     1202 <main+0xb2>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12b8 <main+0x168>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x14(%rbp),%r8
mov    $0x3,%esi
mov    $0x4,%r9d
movl   $0xa,(%rsp)
call   1030 <segment_hash@plt>
lea    -0x1b(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x14(%rbp),%r8
mov    $0x3,%r9d
mov    %r9d,%esi
movl   $0xb,(%rsp)
call   1030 <segment_hash@plt>
lea    -0x1b(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1b(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x14(%rbp),%r8
mov    $0x6,%esi
mov    $0x2,%r9d
movl   $0xd,(%rsp)
call   1030 <segment_hash@plt>
lea    -0x1b(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
cmp    $0x3,%edi
jne    1248 <main+0xf8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0x16(%rsp),%rcx
lea    0x17(%rsp),%r8
lea    0x18(%rsp),%r9
lea    0xe95(%rip),%rsi
lea    0x15(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x4,%eax
jne    1264 <main+0x114>
mov    0x8(%rbx),%rdx
movl   $0xa,(%rsp)
lea    0x19(%rsp),%r15
lea    0x15(%rsp),%r12
mov    %r15,%rdi
mov    $0x3,%esi
mov    %r14,%rcx
mov    %r12,%r8
mov    $0x4,%r9d
call   1030 <segment_hash@plt>
lea    0xe8b(%rip),%r13
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    0x8(%rbx),%rdx
movl   $0xb,(%rsp)
mov    %r15,%rdi
mov    $0x3,%esi
mov    %r14,%rcx
mov    %r12,%r8
mov    $0x3,%r9d
call   1030 <segment_hash@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
mov    0x8(%rbx),%rdx
movl   $0xd,(%rsp)
mov    %r15,%rdi
mov    $0x6,%esi
mov    %r14,%rcx
mov    %r12,%r8
mov    $0x2,%r9d
call   1030 <segment_hash@plt>
lea    0xe2a(%rip),%rdi
mov    %r15,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
jmp    127e <main+0x12e>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    127e <main+0x12e>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: cloak <secret> <ip address>\0A\00"
@.str.1 = [20 x i8] c"%hhd.%hhd.%hhd.%hhd\00"
@.str.2 = [42 x i8] c"IP address must be in dotted quad format\0A\00"
@.str.3 = [4 x i8] c"%s.\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca [7 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %62
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %8
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 3
%29 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %24, i8* %26, i8* %28)
%30 = icmp ne i32 4, %29
br i1 %30, label %31, label %34
31: ; preds = %14
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %62
34: ; preds = %14
%35 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i64, i64* %8
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%41 = call i32 @segment_hash(i8* %35, i32 3, i8* %38, i64 %39, i8* %40, i32 4, i32 10)
%42 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i64, i64* %8
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%50 = call i32 @segment_hash(i8* %44, i32 3, i8* %47, i64 %48, i8* %49, i32 3, i32 11)
%51 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %51)
%53 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i64, i64* %8
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%59 = call i32 @segment_hash(i8* %53, i32 6, i8* %56, i64 %57, i8* %58, i32 2, i32 13)
%60 = getelementptr inbounds [7 x i8], [7 x i8]* %7, i64 0, i64 0
%61 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %34, %31, %11
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: cloak <secret> <ip address>\0A\00"
@.str.1 = [20 x i8] c"%hhd.%hhd.%hhd.%hhd\00"
@.str.2 = [42 x i8] c"IP address must be in dotted quad format\0A\00"
@.str.3 = [4 x i8] c"%s.\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = alloca [7 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %35
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%20 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %17, i8* %18, i8* %19)
%21 = icmp eq i32 %20, 4
br i1 %21, label %25, label %22
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
br label %35
25: ; preds = %11
%26 = load i8*, i8** %12
%27 = call i32 @segment_hash(i8* %6, i32 3, i8* %26, i64 %14, i8* %5, i32 4, i32 10)
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%29 = load i8*, i8** %12
%30 = call i32 @segment_hash(i8* %6, i32 3, i8* %29, i64 %14, i8* %5, i32 3, i32 11)
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%32 = load i8*, i8** %12
%33 = call i32 @segment_hash(i8* %6, i32 6, i8* %32, i64 %14, i8* %5, i32 2, i32 13)
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %35
35: ; preds = %25, %22, %8
%36 = phi i32 [ 1, %8 ], [ 2, %22 ], [ 0, %25 ]
ret i32 %36
}