#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 */
char *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
char *get_tweet_val(char *key, char *twitter_resp) {
  char *quote_key = calloc((1 + strlen(key)) * sizeof(char) + 1, sizeof(char));
  strncpy(quote_key, "\"", 1);
  strcat(quote_key, key);
  char *key_pt = strstr(twitter_resp, quote_key);
  if (key_pt == NULL) {
    return NULL;
  }
  char *head = strstr(key_pt, ":\"") + 2;
  char *tail = strchr(head, '\"');
  if (tail == NULL) {
    printf("Error in Twitter response json. Try again.\n");
    exit(1);
  }
  char *buff = calloc((tail - head) * sizeof(char) + 1, sizeof(char));
  memcpy(buff, head, tail - head);
  return buff;
}


x86 assembly (clang, -O0):
<get_tweet_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1211 <get_tweet_val+0x81>
movq   $0x0,-0x8(%rbp)
jmp    12a1 <get_tweet_val+0x111>
mov    -0x28(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10b0 <strstr@plt>
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x22,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    125c <get_tweet_val+0xcc>
lea    0xdb6(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1080 <memcpy@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tweet_val>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
lea    0x2(%rax),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xe4a(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     122c <get_tweet_val+0x9c>
lea    0xe1a(%rip),%rsi
mov    %rax,%rdi
call   10b0 <strstr@plt>
mov    %rax,%r14
add    $0x2,%r14
mov    %r14,%rdi
mov    $0x22,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1238 <get_tweet_val+0xa8>
mov    %rax,%rbx
sub    %r14d,%ebx
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <memcpy@plt>
jmp    122f <get_tweet_val+0x9f>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdc4(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@.str.1 = [3 x i8] c":\22\00"
@.str.2 = [44 x i8] c"Error in Twitter response json. Try again.\0A\00"
define i8* @get_tweet_val(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 1, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = add i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @calloc(i32 %17, i32 1)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = call i8* @strstr(i8* %24, i8* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %2
store i8* null, i8** %3
br label %61
30: ; preds = %2
%31 = load i8*, i8** %7
%32 = call i8* @strstr(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = call i8* @strchr(i8* %34, i8 signext 34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %30
%42 = load i8*, i8** %9
%43 = load i8*, i8** %8
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = mul i64 %46, 1
%48 = add i64 %47, 1
%49 = trunc i64 %48 to i32
%50 = call i8* @calloc(i32 %49, i32 1)
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = load i8*, i8** %8
%53 = load i8*, i8** %9
%54 = load i8*, i8** %8
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = trunc i64 %57 to i32
%59 = call i32 @memcpy(i8* %51, i8* %52, i32 %58)
%60 = load i8*, i8** %10
store i8* %60, i8** %3
br label %61
61: ; preds = %41, %29
%62 = load i8*, i8** %3
ret i8* %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"\22\00"
@.str.1 = [3 x i8] c":\22\00"
@str = [43 x i8] c"Error in Twitter response json. Try again.\00"
define i8* @get_tweet_val(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add i32 %3, 2
%5 = tail call i8* @calloc(i32 %4, i32 1)
%6 = tail call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = tail call i32 @strcat(i8* %5, i8* %0)
%8 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) %5)
%9 = icmp eq i8* %8, null
br i1 %9, label %26, label %10
10: ; preds = %2
%11 = tail call i8* @strstr(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i8, i8* %11, i64 2
%13 = tail call i8* @strchr(i8* %12, i8 signext 34)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = ptrtoint i8* %13 to i64
%20 = ptrtoint i8* %12 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = add i32 %22, 1
%24 = tail call i8* @calloc(i32 %23, i32 1)
%25 = tail call i32 @memcpy(i8* %24, i8* %12, i32 %22)
br label %26
26: ; preds = %2, %18
%27 = phi i8* [ %24, %18 ], [ null, %2 ]
ret i8* %27
}