#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*/ thingy;
typedef int /*<<< orphan*/ SHA_CTX;

/* Variables and functions */
int /*<<< orphan*/ SHA1(char *, int, unsigned char *);
unsigned int htonl(int);
unsigned short htons(int);
int /*<<< orphan*/ memcpy(unsigned char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  struct {
    unsigned short ssize;
    union {
      unsigned short slen;
      unsigned char slenc[2];
    } uni;
    unsigned int pcrsize;
    unsigned char pcr[20];
  } thingy;
  SHA_CTX sc;
  unsigned char hash[20];
  char *p;
  int i;
  char *pcr0 = "\x16\xCD\xD4\xEA\xA9\x47\x12\x30\xEB\x05"
               "\x99\x36\xE8\xD9\x4D\x4F\xB0\x30\x73\x16";
  char *pcr1 = "\x5B\x93\xBB\xA0\xA6\x64\xA7\x10\x52\x59"
               "\x4A\x70\x95\xB2\x07\x75\x77\x03\x45\x0B";
  char *pcr4 = "\x80\x34\x8A\xB9\xE6\x53\x27\x9F\x5E\x62"
               "\xB2\x1C\x2D\x6C\x0E\x9E\x88\xBE\xE1\x63";
  char *pcr9 = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
               "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  thingy.ssize = htons(2);
  thingy.uni.slen = 1 << 0;
  thingy.pcrsize = htonl(20);
  memcpy(thingy.pcr, pcr0, 20);
  SHA1((char *)&thingy, sizeof(thingy), hash);
  for (i = 0; i < 20; i++)
    printf("%02x ", hash[i]);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xea4(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    $0x2,%edi
call   1030 <htons@plt>
mov    %ax,-0x30(%rbp)
movw   $0x1,-0x2e(%rbp)
mov    $0x14,%edi
call   1050 <htonl@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
mov    -0x68(%rbp),%rsi
mov    $0x14,%edx
call   1060 <memcpy@plt>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    $0x1c,%esi
call   1070 <SHA1@plt>
movl   $0x0,-0x5c(%rbp)
cmpl   $0x14,-0x5c(%rbp)
jge    1214 <main+0xc4>
movslq -0x5c(%rbp),%rax
movzbl -0x50(%rbp,%rax,1),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11e5 <main+0x95>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    $0x2,%edi
call   1040 <htons@plt>
mov    %ax,0x20(%rsp)
movw   $0x1,0x22(%rsp)
mov    $0x14,%edi
call   1060 <htonl@plt>
mov    %eax,0x24(%rsp)
lea    0x28(%rsp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x14,%edx
call   1070 <memcpy@plt>
lea    0x20(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x1c,%esi
call   1080 <SHA1@plt>
movzbl (%rsp),%esi
lea    0xe59(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x1(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x2(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x3(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x5(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x6(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x7(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xd(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xe(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0xf(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x11(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x12(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl 0x13(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.anon = type { i16, %union.anon, i32, [20 x i8] }
%union.anon = type { i16 }
@.str = [21 x i8] c"\16\CD\D4\EA\A9G\120\EB\05\996\E8\D9MO\B00s\16\00"
@.str.1 = [21 x i8] c"[\93\BB\A0\A6d\A7\10RYJp\95\B2\07uw\03E\0B\00"
@.str.2 = [21 x i8] c"\804\8A\B9\E6S'\9F^b\B2\1C-l\0E\9E\88\BE\E1c\00"
@.str.3 = [21 x i8] zeroinitializer
@.str.4 = [6 x i8] c"%02x \00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.anon
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %12
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8** %14
%15 = call zeroext i16 @htons(i32 2)
%16 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 0
store i16 %15, i16* %16
%17 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 1
%18 = bitcast %union.anon* %17 to i16*
store i16 1, i16* %18
%19 = call i32 @htonl(i32 20)
%20 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.anon, %struct.anon* %6, i32 0, i32 3
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %21, i64 0, i64 0
%23 = load i8*, i8** %11
%24 = call i32 @memcpy(i8* %22, i8* %23, i32 20)
%25 = bitcast %struct.anon* %6 to i8*
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%27 = call i32 @SHA1(i8* %25, i32 28, i8* %26)
store i32 0, i32* %10
br label %28
28: ; preds = %38, %2
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 20
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %31
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %28
41: ; preds = %28
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.anon = type { i16, %union.anon, i32, [20 x i8] }
%union.anon = type { i16 }
@.str = [21 x i8] c"\16\CD\D4\EA\A9G\120\EB\05\996\E8\D9MO\B00s\16\00"
@.str.4 = [6 x i8] c"%02x \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.anon
%4 = alloca [20 x i8]
%5 = bitcast %struct.anon* %3 to i8*
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = tail call zeroext i16 @htons(i32 2)
%8 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 0
store i16 %7, i16* %8
%9 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 1, i32 0
store i16 1, i16* %9
%10 = tail call i32 @htonl(i32 20)
%11 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.anon, %struct.anon* %3, i64 0, i32 3, i64 0
%13 = call i32 @memcpy(i8* %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 20)
%14 = call i32 @SHA1(i8* %5, i32 28, i8* %6)
%15 = load i8, i8* %6
%16 = zext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 3
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 4
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 5
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 6
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 7
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 8
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 9
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 10
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 11
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %60)
%62 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 12
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 13
%67 = load i8, i8* %66
%68 = zext i8 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %68)
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 14
%71 = load i8, i8* %70
%72 = zext i8 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %72)
%74 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 15
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %76)
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 16
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %80)
%82 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 17
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %84)
%86 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 18
%87 = load i8, i8* %86
%88 = zext i8 %87 to i32
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %88)
%90 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 19
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %92)
%94 = call i32 @putchar(i32 10)
ret i32 0
}