#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*/ uint8_t;
typedef int uint32_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ PHS(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *, int,
                       void *, int, int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, scalar_t__);
void *phs_thread(void *thread_no) {
  uint8_t out[16];
  struct timeval start, end;
  gettimeofday(&start, NULL);
  PHS(out, sizeof out, (uint8_t *)"secret", 6, thread_no, 4, 10000, 16);
  gettimeofday(&end, NULL);
  printf("Thread %d: %ldus\n", *((uint32_t *)thread_no),
         1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec);
  return NULL;
}


x86 assembly (clang, -O0):
<phs_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%r8
mov    $0x40,%esi
lea    0xea0(%rip),%rdx
mov    $0x6,%ecx
mov    $0x4,%r9d
movl   $0x2710,(%rsp)
movl   $0x10,0x8(%rsp)
call   1050 <PHS@plt>
lea    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
mov    -0x70(%rbp),%eax
sub    -0x60(%rbp),%eax
imul   $0xf4240,%eax,%eax
movslq %eax,%rdx
add    -0x68(%rbp),%rdx
sub    -0x58(%rbp),%rdx
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<phs_thread>:
push   %rbx
sub    $0x60,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xeb5(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x40,%esi
mov    $0x6,%ecx
mov    %rbx,%r8
mov    $0x4,%r9d
push   $0x10
push   $0x2710
call   1050 <PHS@plt>
add    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rbx),%esi
movslq (%rsp),%rax
movslq 0x10(%rsp),%rcx
sub    %rcx,%rax
imul   $0xf4240,%rax,%rax
mov    0x8(%rsp),%rdx
sub    0x18(%rsp),%rdx
add    %rax,%rdx
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [7 x i8] c"secret\00"
@.str.1 = [18 x i8] c"Thread %d: %ldus\0A\00"
define i8* @phs_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca [16 x i32]
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
store i8* %0, i8** %2
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 0
%8 = load i8*, i8** %2
%9 = call i32 @PHS(i32* %7, i32 64, i32* bitcast ([7 x i8]* @.str to i32*), i32 6, i8* %8, i32 4, i32 10000, i32 16)
%10 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%11 = load i8*, i8** %2
%12 = bitcast i8* %11 to i32*
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
%19 = mul nsw i32 1000000, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%22 = load i64, i64* %21
%23 = add nsw i64 %20, %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sub nsw i64 %23, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i64 %26)
ret i8* null
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [7 x i8] c"secret\00"
@.str.1 = [18 x i8] c"Thread %d: %ldus\0A\00"
define noalias i8* @phs_thread(i8* %0) {
%2 = alloca [16 x i32]
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast [16 x i32]* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%10 = call i32 @PHS(i32* %9, i32 64, i32* bitcast ([7 x i8]* @.str to i32*), i32 6, i8* %0, i32 4, i32 10000, i32 16)
%11 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%12 = bitcast i8* %0 to i32*
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
%19 = mul nsw i32 %18, 1000000
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%24 = load i64, i64* %23
%25 = sub i64 %22, %24
%26 = add i64 %25, %20
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13, i64 %26)
ret i8* null
}