#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*/ fputc(char, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
long strlen(char *);
int main() {
  char *buffer = malloc(50);
  char buff1[50] = "How now brown cow.";
  buffer = buff1;
  printf("buff1 = %s\n", buff1);
  printf("buffer = %s\n", buffer);
  for (long x = strlen(buffer); x != 0; x--) {
    fputc(*buffer, stdout);
    fputc('\n', stdout);
    printf("length of buffer = %ld, buffer[%ld] = %c\n", strlen(buffer), x,
           *buffer);
    *buffer++;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe88(%rip),%rsi
mov    $0x32,%edx
call   1060 <memcpy@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1232 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rsi
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x58(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x58(%rbp)
jmp    11bb <main+0x6b>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
movaps 0xede(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea6(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
lea    0xec6(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     11ef <main+0xbf>
mov    %rax,%r14
mov    0x2e3f(%rip),%r12
lea    0xea3(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
mov    (%r12),%esi
call   1050 <fputc@plt>
mov    (%r12),%esi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movsbl (%rbx),%ecx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r14
jne    11b0 <main+0x80>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.buff1 = [50 x i8] c"How now brown cow.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"buff1 = %s\0A\00"
@.str.1 = [13 x i8] c"buffer = %s\0A\00"
@stdout = global i32 0
@.str.2 = [42 x i8] c"length of buffer = %ld, buffer[%ld] = %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [50 x i8]
%4 = alloca i64
store i32 0, i32* %1
%5 = call i8* @malloc(i32 50)
store i8* %5, i8** %2
%6 = bitcast [50 x i8]* %3 to i8*
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %2
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %2
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %4
br label %14
14: ; preds = %34, %0
%15 = load i64, i64* %4
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = load i32, i32* @stdout
%21 = call i32 @fputc(i8 signext %19, i32 %20)
%22 = load i32, i32* @stdout
%23 = call i32 @fputc(i8 signext 10, i32 %22)
%24 = load i8*, i8** %2
%25 = call i64 @strlen(i8* %24)
%26 = load i64, i64* %4
%27 = load i8*, i8** %2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %25, i64 %26, i32 %29)
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %2
%33 = load i8, i8* %31
br label %34
34: ; preds = %17
%35 = load i64, i64* %4
%36 = add nsw i64 %35, -1
store i64 %36, i64* %4
br label %14
37: ; preds = %14
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@__const.main.buff1 = [50 x i8] c"How now brown cow.\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [12 x i8] c"buff1 = %s\0A\00"
@.str.1 = [13 x i8] c"buffer = %s\0A\00"
@stdout = global i32 0
@.str.2 = [42 x i8] c"length of buffer = %ld, buffer[%ld] = %c\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i64 @strlen(i8* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %8, %0
ret i32 0
8: ; preds = %0, %8
%9 = phi i64 [ %21, %8 ], [ %5, %0 ]
%10 = phi i8* [ %20, %8 ], [ %2, %0 ]
%11 = load i8, i8* %10
%12 = load i32, i32* @stdout
%13 = call i32 @fputc(i8 signext %11, i32 %12)
%14 = load i32, i32* @stdout
%15 = call i32 @fputc(i8 signext 10, i32 %14)
%16 = call i64 @strlen(i8* %10)
%17 = load i8, i8* %10
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %16, i64 %9, i32 %18)
%20 = getelementptr inbounds i8, i8* %10, i64 1
%21 = add nsw i64 %9, -1
%22 = icmp eq i64 %21, 0
br i1 %22, label %7, label %8
}