#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 /*<<< orphan*/ free(char *);
char *gg_base64_encode(char const *, int);
int /*<<< orphan*/ gg_hmac_sha1(unsigned char *, int /*<<< orphan*/,
                                unsigned char *, int /*<<< orphan*/,
                                unsigned char *);
char *gg_urlencode_printf(char *, char const *, char const *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *gg_oauth_generate_signature(const char *method, const char *url,
                                  const char *request,
                                  const char *consumer_secret,
                                  const char *token_secret) {
  char *text, *key, *res;
  unsigned char digest[20];
  if (!(text = gg_urlencode_printf("%s&%s&%s", method, url, request)))
    return NULL;
  if (!(key = gg_urlencode_printf("%s&%s", consumer_secret, token_secret))) {
    free(text);
    return NULL;
  }
  printf("text = '%s'\n", text);
  printf("key = '%s'\n", key);
  gg_hmac_sha1((unsigned char *)text, strlen(text), (unsigned char *)key,
               strlen(key), digest);
  free(key);
  free(text);
  res = gg_base64_encode((const char *)digest, 20);
  printf("signature = '%s'\n", res);
  return res;
}


x86 assembly (clang, -O0):
<gg_oauth_generate_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1070 <gg_urlencode_printf@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b4 <gg_oauth_generate_signature+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1285 <gg_oauth_generate_signature+0x125>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1070 <gg_urlencode_printf@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11ee <gg_oauth_generate_signature+0x8e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1285 <gg_oauth_generate_signature+0x125>
mov    -0x38(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    -0x6c(%rbp),%esi
mov    -0x68(%rbp),%rdx
mov    %eax,%ecx
lea    -0x60(%rbp),%r8
call   1080 <gg_hmac_sha1@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1040 <gg_base64_encode@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xdaa(%rip),%rdi
call   1060 <printf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gg_oauth_generate_signature>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %rdi,%rsi
lea    0xe7f(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <gg_urlencode_printf@plt>
test   %rax,%rax
je     1232 <gg_oauth_generate_signature+0xd2>
mov    %rax,%r15
lea    0xe66(%rip),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <gg_urlencode_printf@plt>
test   %rax,%rax
je     1228 <gg_oauth_generate_signature+0xc8>
mov    %rax,%r14
lea    0xe50(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
lea    0xe4e(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r12
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %eax,%ecx
mov    %r12,%r8
call   1080 <gg_hmac_sha1@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    $0x14,%esi
call   1040 <gg_base64_encode@plt>
mov    %rax,%rbx
lea    0xe04(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
jmp    1232 <gg_oauth_generate_signature+0xd2>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s&%s&%s\00"
@.str.1 = [6 x i8] c"%s&%s\00"
@.str.2 = [13 x i8] c"text = '%s'\0A\00"
@.str.3 = [12 x i8] c"key = '%s'\0A\00"
@.str.4 = [18 x i8] c"signature = '%s'\0A\00"
define i8* @gg_oauth_generate_signature(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca [20 x i8]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = load i8*, i8** %7
%17 = load i8*, i8** %8
%18 = load i8*, i8** %9
%19 = call i8* (i8*, i8*, i8*, ...) @gg_urlencode_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17, i8* %18)
store i8* %19, i8** %12
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %5
store i8* null, i8** %6
br label %52
22: ; preds = %5
%23 = load i8*, i8** %10
%24 = load i8*, i8** %11
%25 = call i8* (i8*, i8*, i8*, ...) @gg_urlencode_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %24)
store i8* %25, i8** %13
%26 = icmp ne i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = load i8*, i8** %12
%29 = call i32 @free(i8* %28)
store i8* null, i8** %6
br label %52
30: ; preds = %22
%31 = load i8*, i8** %12
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %13
%34 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %12
%36 = load i8*, i8** %12
%37 = call i32 @strlen(i8* %36)
%38 = load i8*, i8** %13
%39 = load i8*, i8** %13
%40 = call i32 @strlen(i8* %39)
%41 = getelementptr inbounds [20 x i8], [20 x i8]* %15, i64 0, i64 0
%42 = call i32 @gg_hmac_sha1(i8* %35, i32 %37, i8* %38, i32 %40, i8* %41)
%43 = load i8*, i8** %13
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %12
%46 = call i32 @free(i8* %45)
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %15, i64 0, i64 0
%48 = call i8* @gg_base64_encode(i8* %47, i32 20)
store i8* %48, i8** %14
%49 = load i8*, i8** %14
%50 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %14
store i8* %51, i8** %6
br label %52
52: ; preds = %30, %27, %21
%53 = load i8*, i8** %6
ret i8* %53
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s&%s&%s\00"
@.str.1 = [6 x i8] c"%s&%s\00"
@.str.2 = [13 x i8] c"text = '%s'\0A\00"
@.str.3 = [12 x i8] c"key = '%s'\0A\00"
@.str.4 = [18 x i8] c"signature = '%s'\0A\00"
define i8* @gg_oauth_generate_signature(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [20 x i8]
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%8 = tail call i8* (i8*, i8*, i8*, ...) @gg_urlencode_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i8* %2)
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %5
%11 = tail call i8* (i8*, i8*, i8*, ...) @gg_urlencode_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %4)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @free(i8* %8)
br label %25
15: ; preds = %10
%16 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%18 = tail call i32 @strlen(i8* %8)
%19 = tail call i32 @strlen(i8* %11)
%20 = call i32 @gg_hmac_sha1(i8* %8, i32 %18, i8* %11, i32 %19, i8* %7)
%21 = call i32 @free(i8* %11)
%22 = call i32 @free(i8* %8)
%23 = call i8* @gg_base64_encode(i8* %7, i32 20)
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %5, %15, %13
%26 = phi i8* [ %23, %15 ], [ null, %13 ], [ null, %5 ]
ret i8* %26
}