#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  char *pw_dir;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
TYPE_1__ *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ getuid();
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *getKey(char *filename) {
  char *homedir = getpwuid(getuid())->pw_dir;
  char *keydir = "/.tweet/";
  char *tweetdir = malloc((strlen(homedir) * sizeof(char)) +
                          (strlen(keydir) * sizeof(char)) +
                          (strlen(filename) * sizeof(char)) + 1);
  strcpy(tweetdir, homedir);
  strcat(tweetdir, keydir);
  strcat(tweetdir, filename);
  FILE *fp = fopen(tweetdir, "a+");
  if (fp == NULL) {
    perror("Error");
  }
  char *buff = malloc(50);
  fscanf(fp, "%s", buff);
  fclose(fp);
  return buff;
}


x86 assembly (clang, -O0):
<getKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
lea    0xe38(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
shl    $0x0,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1276 <getKey+0xd6>
lea    0xd9b(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x32,%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xd7f(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getKey>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <getuid@plt>
mov    %eax,%edi
call   1050 <getpwuid@plt>
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
lea    0xe32(%rip),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <strlen@plt>
add    %r12d,%ebp
lea    (%rax,%rbp,1),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10c0 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10c0 <strcat@plt>
lea    0xdf0(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     125c <getKey+0xbc>
mov    $0x32,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
lea    0xdd5(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1080 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda9(%rip),%rdi
call   10b0 <perror@plt>
jmp    1229 <getKey+0x89>

LLVM IR (-O0):
%struct.TYPE_2__ = type { i8* }
@.str = [9 x i8] c"/.tweet/\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [3 x i8] c"%s\00"
define i8* @getKey(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = call i32 (...) @getuid()
%9 = call %struct.TYPE_2__* @getpwuid(i32 %8)
%10 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %9, i32 0, i32 0
%11 = load i8*, i8** %10
store i8* %11, i8** %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 1
%20 = add i64 %15, %19
%21 = load i8*, i8** %2
%22 = call i32 @strlen(i8* %21)
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = add i64 %20, %24
%26 = add i64 %25, 1
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = load i8*, i8** %3
%31 = call i32 @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %5
%33 = load i8*, i8** %4
%34 = call i32 @strcat(i8* %32, i8* %33)
%35 = load i8*, i8** %5
%36 = load i8*, i8** %2
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = load i8*, i8** %5
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %1
%43 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %1
%45 = call i8* @malloc(i32 50)
store i8* %45, i8** %7
%46 = load i32*, i32** %6
%47 = load i8*, i8** %7
%48 = call i32 @fscanf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %7
ret i8* %51
}

LLVM IR (-O2):
%struct.TYPE_2__ = type { i8* }
@.str = [9 x i8] c"/.tweet/\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [6 x i8] c"Error\00"
@.str.3 = [3 x i8] c"%s\00"
define i8* @getKey(i8* %0) {
%2 = tail call i32 (...) @getuid()
%3 = tail call %struct.TYPE_2__* @getpwuid(i32 %2)
%4 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %3, i64 0, i32 0
%5 = load i8*, i8** %4
%6 = tail call i32 @strlen(i8* %5)
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @strlen(i8* %0)
%9 = add i32 %6, 1
%10 = add i32 %9, %7
%11 = add i32 %10, %8
%12 = tail call i8* @malloc(i32 %11)
%13 = tail call i32 @strcpy(i8* %12, i8* %5)
%14 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @strcat(i8* %12, i8* %0)
%16 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %1
%21 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%22 = tail call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = tail call i32 @fclose(i32* %16)
ret i8* %21
}