#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int f(char *s1, char *s2) {
  if (strlen(s1) != strlen(s2))
    return 0;
  int n = strlen(s1);
  char *tmp = (char *)malloc(2 * n * sizeof(char));
  strcpy(tmp, s1);
  strcpy(tmp + n, s1);
  printf("tmp = %s\n", tmp);
  if ((strstr(tmp, s2)) != NULL) {
    free(tmp);
    return 1;
  }
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
je     119e <f+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    122e <f+0xce>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     121e <f+0xbe>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    122e <f+0xce>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
xor    %ebp,%ebp
cmp    %eax,%ebx
jne    11dc <f+0x7c>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0x0(%rbp,%rbp,1),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
movslq %ebp,%rdi
add    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe48(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"tmp = %s\0A\00"
define i32 @f(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = icmp ne i32 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %45
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = mul nsw i32 2, %17
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %7
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8*, i8** %4
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %7
%34 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %7
%36 = load i8*, i8** %5
%37 = call i32* @strstr(i8* %35, i8* %36)
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %14
%40 = load i8*, i8** %7
%41 = call i32 @free(i8* %40)
store i32 1, i32* %3
br label %45
42: ; preds = %14
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
store i32 0, i32* %3
br label %45
45: ; preds = %42, %39, %13
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [10 x i8] c"tmp = %s\0A\00"
define i32 @f(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = shl nsw i32 %7, 1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strcpy(i8* %10, i8* %0)
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = tail call i32 @strcpy(i8* %13, i8* %0)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %10)
%16 = tail call i32* @strstr(i8* dereferenceable(1) %10, i8* dereferenceable(1) %1)
%17 = icmp ne i32* %16, null
%18 = tail call i32 @free(i8* %10)
%19 = zext i1 %17 to i32
br label %20
20: ; preds = %6, %2
%21 = phi i32 [ 0, %2 ], [ %19, %6 ]
ret i32 %21
}