#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 */
struct apr_slice {
  int dummy;
};

/* Variables and functions */
struct apr_slice *apr_alloc(int /*<<< orphan*/);
int /*<<< orphan*/ apr_free();
char *apr_get_ptr(struct apr_slice *);
int /*<<< orphan*/ apr_init();
int /*<<< orphan*/ apr_realease(struct apr_slice *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *);
int main() {
  char *q;
  struct apr_slice *q_;
  apr_init();
  while (1) {
    q_ = apr_alloc(0);
    q = apr_get_ptr(q_);
    if (q != NULL) {
      sprintf(q, "helloworld");
      printf("%s\n", q);
    } else {
      printf("error\n");
    }
    apr_realease(q_);
    sleep(1);
  }
  apr_free();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <apr_init@plt>
xor    %edi,%edi
call   1050 <apr_alloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <apr_get_ptr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d0 <main+0x60>
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11de <main+0x6e>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <apr_realease@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    1186 <main+0x16>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <apr_init@plt>
lea    0xe98(%rip),%r14
movabs $0x726f776f6c6c6568,%r15
77 6f 72
jmp    119a <main+0x3a>
nop
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <apr_realease@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
xor    %edi,%edi
call   1050 <apr_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <apr_get_ptr@plt>
test   %rax,%rax
je     1180 <main+0x20>
mov    %r15,(%rax)
movl   $0x646c72,0x7(%rax)
mov    %rax,%rdi
jmp    1183 <main+0x23>

LLVM IR (-O0):
%struct.apr_slice = type { i32 }
@.str = [11 x i8] c"helloworld\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [7 x i8] c"error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.apr_slice*
store i32 0, i32* %1
%4 = call i32 (...) @apr_init()
br label %5
5: ; preds = %0, %18
%6 = call %struct.apr_slice* @apr_alloc(i32 0)
store %struct.apr_slice* %6, %struct.apr_slice** %3
%7 = load %struct.apr_slice*, %struct.apr_slice** %3
%8 = call i8* @apr_get_ptr(%struct.apr_slice* %7)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = load i8*, i8** %2
%13 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %18
16: ; preds = %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load %struct.apr_slice*, %struct.apr_slice** %3
%20 = call i32 @apr_realease(%struct.apr_slice* %19)
%21 = call i32 @sleep(i32 1)
br label %5
}

LLVM IR (-O2):
%struct.apr_slice = type { i32 }
@.str = [11 x i8] c"helloworld\00"
@str = [6 x i8] c"error\00"
define i32 @main() {
%1 = tail call i32 (...) @apr_init()
br label %2
2: ; preds = %10, %0
%3 = tail call %struct.apr_slice* @apr_alloc(i32 0)
%4 = tail call i8* @apr_get_ptr(%struct.apr_slice* %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %4, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 11, i1 false)
%7 = tail call i32 @puts(i8* %4)
br label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @apr_realease(%struct.apr_slice* %3)
%12 = tail call i32 @sleep(i32 1)
br label %2
}