#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*/ printf(char *);
unsigned int smellslike_bittorrent_DHT(unsigned char const *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int smells_selftest_bittorrent_dht(void) {
  unsigned i;
  static const char *examples[] = {
      "d1:ad2:id20:.z..zfOI..d.IXV...UPe1:q4:ping1:t4:.c-.1:v4:UTs.1:y1:qe",
      "d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe",
      "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re",
      "d1:ad2:id20:abcdefghij01234567896:target20:mnopqrstuvwxyz123456e1:q9:"
      "find_node1:t2:aa1:y1:qe",
      "d1:rd2:id20:0123456789abcdefghij5:nodes9:def456...e1:t2:aa1:y1:re",
      "d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz123456e1:q9:"
      "get_peers1:t2:aa1:y1:qe",
      "d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:"
      "idhtnmee1:t2:aa1:y1:re",
      "d1:rd2:id20:abcdefghij01234567895:nodes9:def456...5:token8:aoeusnthe1:"
      "t2:aa1:y1:re",
      "d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz1234564:"
      "porti6881e5:token8:aoeusnthe1:q13:announce_peer1:t2:aa1:y1:qe",
      "d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re",
      0};
  for (i = 0; examples[i]; i++) {
    unsigned x;
    x = smellslike_bittorrent_DHT((const unsigned char *)examples[i],
                                  strlen(examples[i]));
    if (!x) {
      printf("smells:bittorent:dht: failed\n");
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<smells_selftest_bittorrent_dht>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2ef5(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
je     11c2 <smells_selftest_bittorrent_dht+0x92>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2ede(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
lea    0x2eca(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11af <smells_selftest_bittorrent_dht+0x7f>
lea    0x113e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <smells_selftest_bittorrent_dht+0x99>
jmp    11b4 <smells_selftest_bittorrent_dht+0x84>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113f <smells_selftest_bittorrent_dht+0xf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smells_selftest_bittorrent_dht>:
push   %rbx
lea    0xec8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xeeb(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xf03(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xf12(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xf4e(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xf6f(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xfb2(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xff0(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0x1026(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
test   %eax,%eax
je     126b <smells_selftest_bittorrent_dht+0x13b>
lea    0xe2c(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <smellslike_bittorrent_DHT@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    127c <smells_selftest_bittorrent_dht+0x14c>
lea    0x106a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@smells_selftest_bittorrent_dht.examples = internal global [11 x i8*] [i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str = [68 x i8] c"d1:ad2:id20:.z..zfOI..d.IXV...UPe1:q4:ping1:t4:.c-.1:v4:UTs.1:y1:qe\00"
@.str.1 = [57 x i8] c"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe\00"
@.str.2 = [48 x i8] c"d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re\00"
@.str.3 = [93 x i8] c"d1:ad2:id20:abcdefghij01234567896:target20:mnopqrstuvwxyz123456e1:q9:find_node1:t2:aa1:y1:qe\00"
@.str.4 = [66 x i8] c"d1:rd2:id20:0123456789abcdefghij5:nodes9:def456...e1:t2:aa1:y1:re\00"
@.str.5 = [96 x i8] c"d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz123456e1:q9:get_peers1:t2:aa1:y1:qe\00"
@.str.6 = [91 x i8] c"d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:idhtnmee1:t2:aa1:y1:re\00"
@.str.7 = [83 x i8] c"d1:rd2:id20:abcdefghij01234567895:nodes9:def456...5:token8:aoeusnthe1:t2:aa1:y1:re\00"
@.str.8 = [130 x i8] c"d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz1234564:porti6881e5:token8:aoeusnthe1:q13:announce_peer1:t2:aa1:y1:qe\00"
@.str.9 = [30 x i8] c"smells:bittorent:dht: failed\0A\00"
define i32 @smells_selftest_bittorrent_dht() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
br label %4
4: ; preds = %26, %0
%5 = load i32, i32* %2
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [11 x i8*], [11 x i8*]* @smells_selftest_bittorrent_dht.examples, i64 0, i64 %6
%8 = load i8*, i8** %7
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %4
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [11 x i8*], [11 x i8*]* @smells_selftest_bittorrent_dht.examples, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [11 x i8*], [11 x i8*]* @smells_selftest_bittorrent_dht.examples, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @smellslike_bittorrent_DHT(i8* %14, i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %10
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %1
br label %30
25: ; preds = %10
br label %26
26: ; preds = %25
%27 = load i32, i32* %2
%28 = add i32 %27, 1
store i32 %28, i32* %2
br label %4
29: ; preds = %4
store i32 0, i32* %1
br label %30
30: ; preds = %29, %23
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [68 x i8] c"d1:ad2:id20:.z..zfOI..d.IXV...UPe1:q4:ping1:t4:.c-.1:v4:UTs.1:y1:qe\00"
@.str.1 = [57 x i8] c"d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe\00"
@.str.2 = [48 x i8] c"d1:rd2:id20:mnopqrstuvwxyz123456e1:t2:aa1:y1:re\00"
@.str.3 = [93 x i8] c"d1:ad2:id20:abcdefghij01234567896:target20:mnopqrstuvwxyz123456e1:q9:find_node1:t2:aa1:y1:qe\00"
@.str.4 = [66 x i8] c"d1:rd2:id20:0123456789abcdefghij5:nodes9:def456...e1:t2:aa1:y1:re\00"
@.str.5 = [96 x i8] c"d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz123456e1:q9:get_peers1:t2:aa1:y1:qe\00"
@.str.6 = [91 x i8] c"d1:rd2:id20:abcdefghij01234567895:token8:aoeusnth6:valuesl6:axje.u6:idhtnmee1:t2:aa1:y1:re\00"
@.str.7 = [83 x i8] c"d1:rd2:id20:abcdefghij01234567895:nodes9:def456...5:token8:aoeusnthe1:t2:aa1:y1:re\00"
@.str.8 = [130 x i8] c"d1:ad2:id20:abcdefghij01234567899:info_hash20:mnopqrstuvwxyz1234564:porti6881e5:token8:aoeusnthe1:q13:announce_peer1:t2:aa1:y1:qe\00"
@str = [29 x i8] c"smells:bittorent:dht: failed\00"
define i32 @smells_selftest_bittorrent_dht() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %40, label %4
4: ; preds = %0
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %40, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %40, label %12
12: ; preds = %8
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %40, label %16
16: ; preds = %12
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %40, label %20
20: ; preds = %16
%21 = tail call i32 @strlen(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.5, i64 0, i64 0))
%22 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %40, label %24
24: ; preds = %20
%25 = tail call i32 @strlen(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.6, i64 0, i64 0))
%26 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %40, label %28
28: ; preds = %24
%29 = tail call i32 @strlen(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.7, i64 0, i64 0))
%30 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %28
%33 = tail call i32 @strlen(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.8, i64 0, i64 0))
%34 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.8, i64 0, i64 0), i32 %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = tail call i32 @strlen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @smellslike_bittorrent_DHT(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36, %32, %28, %24, %20, %16, %12, %8, %4, %0
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %42
42: ; preds = %36, %40
%43 = phi i32 [ 1, %40 ], [ 0, %36 ]
ret i32 %43
}