#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*/ printf(char *, ...);
int strlen(char *);
int main() {
  char str[30 + 1] = "This is a string.";
  char first, last;
  int pos;
  printf("Character position 3: %c\n", str[3]);
  printf("Character position 8: %c\n", str[8]);
  first = str[0];
  last = str[strlen(str) - 1];
  printf("The first and last chrs: %c %c\n", first, last);
  for (pos = strlen(str) - 1; pos >= 0; pos--)
    printf("%c", str[pos]);
  printf("\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec2(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xebc(%rip),%ax
mov    %ax,-0x14(%rbp)
mov    0xeb4(%rip),%al
mov    %al,-0x12(%rbp)
movsbl -0x2d(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x28(%rbp),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%al
mov    %al,-0x31(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    -0x30(%rbp,%rax,1),%al
mov    %al,-0x32(%rbp)
movsbl -0x31(%rbp),%esi
movsbl -0x32(%rbp),%edx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jl     1200 <main+0xe0>
movslq -0x38(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    11d1 <main+0xb1>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movups 0xec3(%rip),%xmm0
movups %xmm0,0xf(%rsp)
movaps 0xea8(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xebc(%rip),%rdi
mov    $0x73,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x61,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%edx
lea    0xeb8(%rip),%rdi
mov    $0x54,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11d6 <main+0x96>
mov    %eax,%ebx
add    $0x1,%rbx
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
movsbl (%rsp,%rax,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11c0 <main+0x80>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str = [31 x i8] c"This is a string.\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [26 x i8] c"Character position 3: %c\0A\00"
@.str.1 = [26 x i8] c"Character position 8: %c\0A\00"
@.str.2 = [32 x i8] c"The first and last chrs: %c %c\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [31 x i8]
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [31 x i8]* %2 to i8*
%7 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 8
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 0
%16 = load i8, i8* %15
store i8 %16, i8* %3
%17 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
store i8 %22, i8* %4
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %26)
%28 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
store i32 %30, i32* %5
br label %31
31: ; preds = %41, %0
%32 = load i32, i32* %5
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %31
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [31 x i8], [31 x i8]* %2, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %34
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %31
44: ; preds = %31
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [31 x i8] c"This is a string.\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [26 x i8] c"Character position 3: %c\0A\00"
@.str.1 = [26 x i8] c"Character position 8: %c\0A\00"
@.str.2 = [32 x i8] c"The first and last chrs: %c %c\0A\00"
@str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca [31 x i8]
%2 = getelementptr inbounds [31 x i8], [31 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 115)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 97)
%5 = call i32 @strlen(i8* %2)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [31 x i8], [31 x i8]* %1, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 84, i32 %10)
%12 = call i32 @strlen(i8* %2)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %0
%15 = zext i32 %12 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ %15, %14 ], [ %18, %16 ]
%18 = add nsw i64 %17, -1
%19 = and i64 %18, 4294967295
%20 = getelementptr inbounds [31 x i8], [31 x i8]* %1, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 @putchar(i32 %22)
%24 = icmp ugt i64 %17, 1
br i1 %24, label %16, label %25
25: ; preds = %16, %0
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}