#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 */
struct tgl_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SHA1(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ add_log_event(struct tgl_state *, int *, int);
int *alloc_log_event(int);
int /*<<< orphan*/ memcpy(int *, unsigned char *, int);
void bl_do_set_auth_key_id(struct tgl_state *TLS, int num, unsigned char *buf) {
  static unsigned char sha1_buffer[20];
  SHA1(buf, 256, sha1_buffer);
  long long fingerprint = *(long long *)(sha1_buffer + 12);
  int *ev = alloc_log_event(8 + 8 + 256);
  ev[0] = 0xedf92e72;
  ev[1] = num;
  *(long long *)(ev + 2) = fingerprint;
  memcpy(ev + 4, buf, 256);
  add_log_event(TLS, ev, 8 + 8 + 256);
}


x86 assembly (clang, -O0):
<bl_do_set_auth_key_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x100,%esi
lea    0x2eed(%rip),%rdx
call   1060 <SHA1@plt>
mov    0x2eed(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x110,%edi
call   1040 <alloc_log_event@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0xedf92e72,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rdi
add    $0x10,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x110,%edx
call   1030 <add_log_event@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bl_do_set_auth_key_id>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x2ef8(%rip),%rdx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <SHA1@plt>
mov    0x2ef0(%rip),%r12
mov    $0x110,%edi
call   1040 <alloc_log_event@plt>
mov    %rax,%rbp
movl   $0xedf92e72,(%rax)
mov    %r15d,0x4(%rax)
mov    %r12,0x8(%rax)
lea    0x10(%rax),%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x110,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <add_log_event@plt>

LLVM IR (-O0):
%struct.tgl_state = type { i32 }
@bl_do_set_auth_key_id.sha1_buffer = internal global [20 x i8] zeroinitializer
define void @bl_do_set_auth_key_id(%struct.tgl_state* %0, i32 %1, i8* %2) {
%4 = alloca %struct.tgl_state*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
store %struct.tgl_state* %0, %struct.tgl_state** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @SHA1(i8* %9, i32 256, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @bl_do_set_auth_key_id.sha1_buffer, i64 0, i64 0))
%11 = load i64, i64* bitcast (i8* getelementptr inbounds ([20 x i8], [20 x i8]* @bl_do_set_auth_key_id.sha1_buffer, i64 0, i64 12) to i64*)
store i64 %11, i64* %7
%12 = call i32* @alloc_log_event(i32 272)
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = getelementptr inbounds i32, i32* %13, i64 0
store i32 -302436750, i32* %14
%15 = load i32, i32* %5
%16 = load i32*, i32** %8
%17 = getelementptr inbounds i32, i32* %16, i64 1
store i32 %15, i32* %17
%18 = load i64, i64* %7
%19 = load i32*, i32** %8
%20 = getelementptr inbounds i32, i32* %19, i64 2
%21 = bitcast i32* %20 to i64*
store i64 %18, i64* %21
%22 = load i32*, i32** %8
%23 = getelementptr inbounds i32, i32* %22, i64 4
%24 = load i8*, i8** %6
%25 = call i32 @memcpy(i32* %23, i8* %24, i32 256)
%26 = load %struct.tgl_state*, %struct.tgl_state** %4
%27 = load i32*, i32** %8
%28 = call i32 @add_log_event(%struct.tgl_state* %26, i32* %27, i32 272)
ret void
}

LLVM IR (-O2):
%struct.tgl_state = type { i32 }
@bl_do_set_auth_key_id.sha1_buffer = internal global [20 x i8] zeroinitializer
define void @bl_do_set_auth_key_id(%struct.tgl_state* %0, i32 %1, i8* %2) {
%4 = tail call i32 @SHA1(i8* %2, i32 256, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @bl_do_set_auth_key_id.sha1_buffer, i64 0, i64 0))
%5 = load i64, i64* bitcast (i8* getelementptr inbounds ([20 x i8], [20 x i8]* @bl_do_set_auth_key_id.sha1_buffer, i64 0, i64 12) to i64*)
%6 = tail call i32* @alloc_log_event(i32 272)
store i32 -302436750, i32* %6
%7 = getelementptr inbounds i32, i32* %6, i64 1
store i32 %1, i32* %7
%8 = getelementptr inbounds i32, i32* %6, i64 2
%9 = bitcast i32* %8 to i64*
store i64 %5, i64* %9
%10 = getelementptr inbounds i32, i32* %6, i64 4
%11 = tail call i32 @memcpy(i32* %10, i8* %2, i32 256)
%12 = tail call i32 @add_log_event(%struct.tgl_state* %0, i32* %6, i32 272)
ret void
}