char *snapchat_request_token(const char *auth_token, int timestamp) {
  const char *const secret = "iEk21fuwZApXlz93750dmW22pw389dPwOk";
  const char *const pattern =
      "0001110111101110001111010101111011010001001110011000110001000110";
  unsigned char *first;
  {
    char *secret_auth_token = concat(secret, auth_token);
    first = snapchat_sha256(secret_auth_token);
    free(secret_auth_token);
  }
  unsigned char *second;
  {
    char *timestamp_s = int_to_str(timestamp);
    char *timestamp_secret = concat(timestamp_s, secret);
    second = snapchat_sha256(timestamp_secret);
    free(timestamp_secret);
    free(timestamp_s);
  }
  char *token;
  {
    int i, pattern_length = (int)strlen(pattern);
    token = malloc(sizeof(char) * (pattern_length + 1));
    for (i = 0; i < pattern_length; i++)
      token[i] = pattern[i] == '0' ? first[i] : second[i];
    token[i] = '\0';
  }
  free(first), free(second);
  return token;
}


x86 assembly (clang, -O0):
<snapchat_request_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1050 <concat@plt>
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x0,%al
call   1040 <snapchat_sha256@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
mov    $0x0,%al
call   1060 <int_to_str@plt>
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1050 <concat@plt>
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    $0x0,%al
call   1040 <snapchat_sha256@plt>
cltq
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x40,-0x58(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    127b <snapchat_request_token+0x12b>
movslq -0x54(%rbp),%rcx
lea    0xdf6(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    124e <snapchat_request_token+0xfe>
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x5c(%rbp)
jmp    125d <snapchat_request_token+0x10d>
mov    -0x38(%rbp),%rax
movslq -0x54(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %al,%dl
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1216 <snapchat_request_token+0xc6>
mov    -0x50(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snapchat_request_token>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%rsi
lea    0xe9b(%rip),%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <concat@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <snapchat_sha256@plt>
movslq %eax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12d,%edi
xor    %eax,%eax
call   1060 <int_to_str@plt>
movslq %eax,%r12
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <concat@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <snapchat_sha256@plt>
movslq %eax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    $0x41,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
lea    0xe4c(%rip),%rax
jmp    11f3 <snapchat_request_token+0xa3>
nopl   0x0(%rax)
movzbl 0x1(%rcx,%rbp,1),%ecx
mov    %cl,0x1(%rbx,%rbp,1)
add    $0x2,%rbp
cmp    $0x40,%rbp
je     1219 <snapchat_request_token+0xc9>
cmpb   $0x30,0x0(%rbp,%rax,1)
mov    %r15,%rcx
je     1200 <snapchat_request_token+0xb0>
mov    %r14,%rcx
movzbl 0x1(%rbp,%rax,1),%edx
movzbl (%rcx,%rbp,1),%ecx
mov    %cl,(%rbx,%rbp,1)
mov    %r15,%rcx
cmp    $0x30,%dl
je     11e0 <snapchat_request_token+0x90>
mov    %r14,%rcx
jmp    11e0 <snapchat_request_token+0x90>
movb   $0x0,0x40(%rbx)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"iEk21fuwZApXlz93750dmW22pw389dPwOk\00"
@.str.1 = [65 x i8] c"0001110111101110001111010101111011010001001110011000110001000110\00"
define i8* @snapchat_request_token(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8** %6
%15 = load i8*, i8** %3
%16 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @concat to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i32 0, i32 0), i8* %15)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @snapchat_sha256 to i32 (i8*, ...)*)(i8* %19)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %7
%23 = load i8*, i8** %8
%24 = load i32, i32* %4
%25 = call i32 (i32, ...) bitcast (i32 (...)* @int_to_str to i32 (i32, ...)*)(i32 %24)
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %10
%28 = load i8*, i8** %10
%29 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @concat to i32 (i8*, i8*, ...)*)(i8* %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i32 0, i32 0))
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %11
%32 = load i8*, i8** %11
%33 = call i32 (i8*, ...) bitcast (i32 (...)* @snapchat_sha256 to i32 (i8*, ...)*)(i8* %32)
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %9
%36 = load i8*, i8** %11
%37 = load i8*, i8** %10
store i32 64, i32* %14
%38 = load i32, i32* %14
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = mul i64 1, %40
%42 = call i8* @malloc(i64 %41)
store i8* %42, i8** %12
store i32 0, i32* %13
br label %43
43: ; preds = %75, %2
%44 = load i32, i32* %13
%45 = load i32, i32* %14
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %78
47: ; preds = %43
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i32 0, i32 0), i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 48
br i1 %53, label %54, label %61
54: ; preds = %47
%55 = load i8*, i8** %7
%56 = load i32, i32* %13
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = zext i8 %59 to i32
br label %68
61: ; preds = %47
%62 = load i8*, i8** %9
%63 = load i32, i32* %13
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
br label %68
68: ; preds = %61, %54
%69 = phi i32 [ %60, %54 ], [ %67, %61 ]
%70 = trunc i32 %69 to i8
%71 = load i8*, i8** %12
%72 = load i32, i32* %13
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
store i8 %70, i8* %74
br label %75
75: ; preds = %68
%76 = load i32, i32* %13
%77 = add nsw i32 %76, 1
store i32 %77, i32* %13
br label %43
78: ; preds = %43
%79 = load i8*, i8** %12
%80 = load i32, i32* %13
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
store i8 0, i8* %82
%83 = load i8*, i8** %7
%84 = load i8*, i8** %9
%85 = load i8*, i8** %12
ret i8* %85
}

LLVM IR (-O2):
@.str = [35 x i8] c"iEk21fuwZApXlz93750dmW22pw389dPwOk\00"
@.str.1 = [65 x i8] c"0001110111101110001111010101111011010001001110011000110001000110\00"
define i8* @snapchat_request_token(i8* %0, i32 %1) {
%3 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @concat to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = sext i32 %3 to i64
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @snapchat_sha256 to i32 (i8*, ...)*)(i8* %5)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
tail call void @free(i8* %5)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @int_to_str to i32 (i32, ...)*)(i32 %1)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 (i8*, i8*, ...) bitcast (i32 (...)* @concat to i32 (i8*, i8*, ...)*)(i8* %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 (i8*, ...) bitcast (i32 (...)* @snapchat_sha256 to i32 (i8*, ...)*)(i8* %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
tail call void @free(i8* %14)
tail call void @free(i8* %11)
%18 = tail call dereferenceable_or_null(65) i8* @malloc(i64 65)
br label %19
19: ; preds = %19, %2
%20 = phi i64 [ 0, %2 ], [ %36, %19 ]
%21 = getelementptr inbounds [65 x i8], [65 x i8]* @.str.1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 48
%24 = select i1 %23, i8* %8, i8* %17
%25 = getelementptr inbounds i8, i8* %24, i64 %20
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 %26, i8* %27
%28 = or i64 %20, 1
%29 = getelementptr inbounds [65 x i8], [65 x i8]* @.str.1, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 48
%32 = select i1 %31, i8* %8, i8* %17
%33 = getelementptr inbounds i8, i8* %32, i64 %28
%34 = load i8, i8* %33
%35 = getelementptr inbounds i8, i8* %18, i64 %28
store i8 %34, i8* %35
%36 = add nuw nsw i64 %20, 2
%37 = icmp eq i64 %36, 64
br i1 %37, label %38, label %19
38: ; preds = %19
%39 = getelementptr inbounds i8, i8* %18, i64 64
store i8 0, i8* %39
tail call void @free(i8* %8)
tail call void @free(i8* %17)
ret i8* %18
}