#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 *str_immutable(char const *);
int cmain(void) {
  const char *immutable_ref1 = str_immutable("hello world");
  const char *immutable_ref2 = str_immutable(immutable_ref1),
             *immutable_ref3 = str_immutable("hello world");
  unsigned int i;
  if (immutable_ref1 == (const char *)0)
    return 1;
  if (immutable_ref2 == (const char *)0)
    return 2;
  if (immutable_ref1 != immutable_ref2)
    return 3;
  for (i = 0; i < (unsigned int)(sizeof("hello world") - 1); i++) {
    if (immutable_ref1[i] != "hello world"[i])
      return 4;
  }
  if (immutable_ref1 != immutable_ref3)
    return 5;
  return 0;
}


x86 assembly (clang, -O0):
<cmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xee1(%rip),%rdi
call   1030 <str_immutable@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <str_immutable@plt>
mov    %rax,-0x18(%rbp)
lea    0xec4(%rip),%rdi
call   1030 <str_immutable@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115c <cmain+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    1201 <cmain+0xf1>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <cmain+0x63>
movl   $0x2,-0x4(%rbp)
jmp    1201 <cmain+0xf1>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     118d <cmain+0x7d>
movl   $0x3,-0x4(%rbp)
jmp    1201 <cmain+0xf1>
movl   $0x0,-0x24(%rbp)
cmpl   $0xb,-0x24(%rbp)
jae    11e0 <cmain+0xd0>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
lea    0xe4b(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11cd <cmain+0xbd>
movl   $0x4,-0x4(%rbp)
jmp    1201 <cmain+0xf1>
jmp    11d2 <cmain+0xc2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1194 <cmain+0x84>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11fa <cmain+0xea>
movl   $0x5,-0x4(%rbp)
jmp    1201 <cmain+0xf1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmain>:
push   %r15
push   %r14
push   %rbx
lea    0xee4(%rip),%r15
mov    %r15,%rdi
call   1030 <str_immutable@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <str_immutable@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <str_immutable@plt>
test   %r14,%r14
je     11af <cmain+0x9f>
test   %rbx,%rbx
je     11b6 <cmain+0xa6>
mov    %rax,%rcx
mov    $0x3,%eax
cmp    %rbx,%r14
jne    11bb <cmain+0xab>
mov    $0x4,%eax
cmpb   $0x68,(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x65,0x1(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x6c,0x2(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x6c,0x3(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x6f,0x4(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x20,0x5(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x77,0x6(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x6f,0x7(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x72,0x8(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x6c,0x9(%r14)
jne    11bb <cmain+0xab>
cmpb   $0x64,0xa(%r14)
jne    11bb <cmain+0xab>
xor    %eax,%eax
cmp    %rcx,%r14
setne  %al
lea    (%rax,%rax,4),%eax
jmp    11bb <cmain+0xab>
mov    $0x1,%eax
jmp    11bb <cmain+0xab>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
define i32 @cmain() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = call i8* @str_immutable(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @str_immutable(i8* %7)
store i8* %8, i8** %3
%9 = call i8* @str_immutable(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %2
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 1, i32* %1
br label %50
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 2, i32* %1
br label %50
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i8*, i8** %3
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 3, i32* %1
br label %50
22: ; preds = %17
store i32 0, i32* %5
br label %23
23: ; preds = %41, %22
%24 = load i32, i32* %5
%25 = icmp ult i32 %24, 11
br i1 %25, label %26, label %44
26: ; preds = %23
%27 = load i8*, i8** %2
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = load i32, i32* %5
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [12 x i8], [12 x i8]* @.str, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %32, %37
br i1 %38, label %39, label %40
39: ; preds = %26
store i32 4, i32* %1
br label %50
40: ; preds = %26
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
%43 = add i32 %42, 1
store i32 %43, i32* %5
br label %23
44: ; preds = %23
%45 = load i8*, i8** %2
%46 = load i8*, i8** %4
%47 = icmp ne i8* %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 5, i32* %1
br label %50
49: ; preds = %44
store i32 0, i32* %1
br label %50
50: ; preds = %49, %48, %39, %21, %16, %12
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
define i32 @cmain() {
%1 = tail call i8* @str_immutable(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @str_immutable(i8* %1)
%3 = tail call i8* @str_immutable(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %1, null
br i1 %4, label %55, label %5
5: ; preds = %0
%6 = icmp eq i8* %2, null
br i1 %6, label %55, label %7
7: ; preds = %5
%8 = icmp eq i8* %1, %2
br i1 %8, label %9, label %55
9: ; preds = %7
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 104
br i1 %11, label %12, label %55
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %1, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 101
br i1 %15, label %16, label %55
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %1, i64 2
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 108
br i1 %19, label %20, label %55
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %1, i64 3
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 108
br i1 %23, label %24, label %55
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %1, i64 4
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 111
br i1 %27, label %28, label %55
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %1, i64 5
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 32
br i1 %31, label %32, label %55
32: ; preds = %28
%33 = getelementptr inbounds i8, i8* %1, i64 6
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 119
br i1 %35, label %36, label %55
36: ; preds = %32
%37 = getelementptr inbounds i8, i8* %1, i64 7
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 111
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = getelementptr inbounds i8, i8* %1, i64 8
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 114
br i1 %43, label %44, label %55
44: ; preds = %40
%45 = getelementptr inbounds i8, i8* %1, i64 9
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 108
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = getelementptr inbounds i8, i8* %1, i64 10
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 100
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = icmp eq i8* %1, %3
%54 = select i1 %53, i32 0, i32 5
br label %55
55: ; preds = %9, %12, %16, %20, %24, %28, %32, %36, %40, %44, %48, %52, %7, %5, %0
%56 = phi i32 [ 1, %0 ], [ 2, %5 ], [ 3, %7 ], [ %54, %52 ], [ 4, %48 ], [ 4, %44 ], [ 4, %40 ], [ 4, %36 ], [ 4, %32 ], [ 4, %28 ], [ 4, %24 ], [ 4, %20 ], [ 4, %16 ], [ 4, %12 ], [ 4, %9 ]
ret i32 %56
}