#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*/ free(char *);
int /*<<< orphan*/ getchar();
char *malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  char *p1 = malloc(8);
  char *p2 = malloc(8);
  char *p3 = malloc(8);
  strncpy(p1, "1234567", 7);
  p1[7] = '\0';
  strncpy(p2, "1234567", 7);
  p2[7] = '\0';
  strncpy(p3, "1234567", 7);
  p3[7] = '\0';
  free(p3);
  getchar();
  free(p2);
  getchar();
  free(p1);
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x18(%rbp),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe42(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x7(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe8a(%rip),%r12
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x7(%r14)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x7(%r15)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x7(%rbx)
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"1234567\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i8* @malloc(i32 8)
store i8* %5, i8** %2
%6 = call i8* @malloc(i32 8)
store i8* %6, i8** %3
%7 = call i8* @malloc(i32 8)
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = call i32 @strncpy(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 7
store i8 0, i8* %11
%12 = load i8*, i8** %3
%13 = call i32 @strncpy(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 7
store i8 0, i8* %15
%16 = load i8*, i8** %4
%17 = call i32 @strncpy(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 7
store i8 0, i8* %19
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
%22 = call i32 (...) @getchar()
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = call i32 (...) @getchar()
%26 = load i8*, i8** %2
%27 = call i32 @free(i8* %26)
%28 = call i32 (...) @getchar()
%29 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"1234567\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%2 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%3 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%4 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%5 = getelementptr inbounds i8, i8* %1, i64 7
store i8 0, i8* %5
%6 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%7 = getelementptr inbounds i8, i8* %2, i64 7
store i8 0, i8* %7
%8 = tail call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%9 = getelementptr inbounds i8, i8* %3, i64 7
store i8 0, i8* %9
%10 = tail call i32 @free(i8* %3)
%11 = tail call i32 (...) @getchar()
%12 = tail call i32 @free(i8* %2)
%13 = tail call i32 (...) @getchar()
%14 = tail call i32 @free(i8* %1)
%15 = tail call i32 (...) @getchar()
%16 = tail call i32 (...) @getchar()
ret i32 0
}