#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 BUFSIZ;
int /*<<< orphan*/ assert(int);
scalar_t__ aws_sigv4_derive_signing_key(char *, char *, char *, char *,
                                        unsigned char **, int *);
scalar_t__ sprintf(char *, char *, unsigned char);
scalar_t__ strcmp(char *, char *);
void test_aws_sigv4_derive_signing_key(void) {
  unsigned char *key;
  int key_len;
  int i;
  char buf[BUFSIZ];
  int n = 0;
  assert(aws_sigv4_derive_signing_key(
             "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY", "20110909",
             "us-east-1", "iam", &key, &key_len) == 0);
  for (i = 0; i < key_len; i++) {
    n += sprintf(buf + n, "%d ", key[i]);
  }
  assert(strcmp(buf,
                "152 241 216 137 254 196 244 66 26 220 82 43 171 12 225 248 46 "
                "105 41 194 98 237 21 229 169 76 144 239 209 227 176 231 ") ==
         0);
}


x86 assembly (clang, -O0):
<test_aws_sigv4_derive_signing_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe7e(%rip),%rdi
lea    0xea0(%rip),%rsi
lea    0xea2(%rip),%rdx
lea    0xea5(%rip),%rcx
lea    -0x8(%rbp),%r8
lea    -0xc(%rbp),%r9
call   1030 <aws_sigv4_derive_signing_key@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1206 <test_aws_sigv4_derive_signing_key+0xc6>
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe5e(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    %rax,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11bc <test_aws_sigv4_derive_signing_key+0x7c>
mov    -0x30(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_aws_sigv4_derive_signing_key>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r15
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe8b(%rip),%rdi
lea    0xead(%rip),%rsi
lea    0xeaf(%rip),%rdx
lea    0xeb2(%rip),%rcx
lea    -0x38(%rbp),%r8
lea    -0x2c(%rbp),%r9
call   1030 <aws_sigv4_derive_signing_key@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11e7 <test_aws_sigv4_derive_signing_key+0xa7>
xor    %ebx,%ebx
lea    0xe8c(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movslq %eax,%r13
lea    (%r12,%r13,1),%rdi
mov    -0x38(%rbp),%rax
movzbl (%rax,%rbx,1),%edx
mov    %r14,%rsi
call   1060 <sprintf@plt>
add    %r13,%rax
add    $0x1,%rbx
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rbx
jl     11c0 <test_aws_sigv4_derive_signing_key+0x80>
lea    0xe56(%rip),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %r15,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [41 x i8] c"wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY\00"
@.str.1 = [9 x i8] c"20110909\00"
@.str.2 = [10 x i8] c"us-east-1\00"
@.str.3 = [4 x i8] c"iam\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [119 x i8] c"152 241 216 137 254 196 244 66 26 220 82 43 171 12 225 248 46 105 41 194 98 237 21 229 169 76 144 239 209 227 176 231 \00"
define void @test_aws_sigv4_derive_signing_key() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8, i64 %8
store i64 %8, i64* %5
store i32 0, i32* %6
%11 = call i64 @aws_sigv4_derive_signing_key(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %1, i32* %2)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
store i32 0, i32* %3
br label %15
15: ; preds = %33, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %10, i64 %21
%23 = load i8*, i8** %1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @sprintf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %27)
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %6
br label %33
33: ; preds = %19
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %15
36: ; preds = %15
%37 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [41 x i8] c"wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY\00"
@.str.1 = [9 x i8] c"20110909\00"
@.str.2 = [10 x i8] c"us-east-1\00"
@.str.3 = [4 x i8] c"iam\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [119 x i8] c"152 241 216 137 254 196 244 66 26 220 82 43 171 12 225 248 46 105 41 194 98 237 21 229 169 76 144 239 209 227 176 231 \00"
define void @test_aws_sigv4_derive_signing_key() {
%1 = alloca i8*
%2 = alloca i32
%3 = bitcast i8** %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i64 @aws_sigv4_derive_signing_key(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %1, i32* %2)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %0, %15
%16 = phi i64 [ %26, %15 ], [ 0, %0 ]
%17 = phi i64 [ %25, %15 ], [ 0, %0 ]
%18 = shl i64 %17, 32
%19 = ashr exact i64 %18, 32
%20 = getelementptr inbounds i8, i8* %8, i64 %19
%21 = load i8*, i8** %1
%22 = getelementptr inbounds i8, i8* %21, i64 %16
%23 = load i8, i8* %22
%24 = call i64 @sprintf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %23)
%25 = add nsw i64 %24, %19
%26 = add nuw nsw i64 %16, 1
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %15, label %30
30: ; preds = %15, %0
%31 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
ret void
}