#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main() {
  FILE *fp = NULL;
  char *aa = "aa";
  char test[32];
  sprintf(test, "%s/haha", aa);
  printf("%s\n", test);
  fp = fopen(test, "r");
  if (NULL == fp) {
    perror("fopen()");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe92(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11c2 <main+0x72>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xea7(%rip),%rsi
lea    0xe9d(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe96(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a4 <main+0x54>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe66(%rip),%rdi
call   1060 <perror@plt>
jmp    1194 <main+0x44>

LLVM IR (-O0):
@.str = [3 x i8] c"aa\00"
@.str.1 = [8 x i8] c"%s/haha\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"fopen()\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [32 x i8]
store i32 0, i32* %1
store i32* null, i32** %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = load i8*, i8** %3
%7 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"aa\00"
@.str.1 = [8 x i8] c"%s/haha\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [8 x i8] c"fopen()\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @fclose(i32* %5)
ret i32 0
}