#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 *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int sub_fun(int x) {
  int i;
  int count = 0;
  char *my_data = malloc(1);
  my_data[0] = 's';
  my_data[1] = 'u';
  my_data[2] = 'b';
  my_data[3] = '\n';
  my_data[4] = '\0';
  for (i = 0; i < 2; i++) {
    count = count + 2;
    ;
    printf("%s", my_data);
  }
  return count + x;
}


x86 assembly (clang, -O0):
<sub_fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x73,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x75,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x62,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0xa,0x3(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x4(%rax)
movl   $0x0,-0x8(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119f <sub_fun+0x7f>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116e <sub_fun+0x4e>
mov    -0xc(%rbp),%eax
add    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_fun>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,0x4(%rax)
lea    0xec2(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
add    $0x4,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @sub_fun(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %4
%6 = call i8* @malloc(i32 1)
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 115, i8* %8
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 117, i8* %10
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 2
store i8 98, i8* %12
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 3
store i8 10, i8* %14
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 4
store i8 0, i8* %16
store i32 0, i32* %3
br label %17
17: ; preds = %25, %1
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 2
store i32 %22, i32* %4
%23 = load i8*, i8** %5
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %17
28: ; preds = %17
%29 = load i32, i32* %4
%30 = load i32, i32* %2
%31 = add nsw i32 %29, %30
ret i32 %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @sub_fun(i32 %0) {
%2 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%3 = getelementptr inbounds i8, i8* %2, i64 4
store i8 0, i8* %3
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%6 = add nsw i32 %0, 4
ret i32 %6
}