#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ read_text_file(char *, int, size_t *, char const *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
bool read_pisound_system_file(char *dst, size_t length, const char *file) {
  char buffer[64];
  size_t n;
  if (!read_text_file(buffer, sizeof(buffer), &n, file))
    return false;
  strncpy(dst, buffer, length);
  if (n > 1)
    dst[strlen(dst) - 1] = '\0';
  return true;
}


x86 assembly (clang, -O0):
<read_pisound_system_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x40,%esi
lea    -0x68(%rbp),%rdx
call   1050 <read_text_file@plt>
cmp    $0x0,%eax
jne    116f <read_pisound_system_file+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11b3 <read_pisound_system_file+0x83>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
cmpq   $0x1,-0x68(%rbp)
jbe    11ac <read_pisound_system_file+0x7c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pisound_system_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdx,%rcx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
mov    $0x40,%esi
call   1050 <read_text_file@plt>
test   %eax,%eax
je     1187 <read_pisound_system_file+0x57>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <strncpy@plt>
mov    $0x1,%ebp
cmpq   $0x2,0x8(%rsp)
jb     1189 <read_pisound_system_file+0x59>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    1189 <read_pisound_system_file+0x59>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_pisound_system_file(i8* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [64 x i8]
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %7
%12 = call i32 @read_text_file(i8* %10, i32 64, i64* %9, i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 0, i32* %4
br label %30
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%18 = load i64, i64* %6
%19 = call i32 @strncpy(i8* %16, i8* %17, i64 %18)
%20 = load i64, i64* %9
%21 = icmp ugt i64 %20, 1
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = load i8*, i8** %5
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %22, %15
store i32 1, i32* %4
br label %30
30: ; preds = %29, %14
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @read_pisound_system_file(i8* %0, i64 %1, i8* %2) {
%4 = alloca [64 x i8]
%5 = alloca i64
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%7 = bitcast i64* %5 to i8*
%8 = call i32 @read_text_file(i8* %6, i32 64, i64* %5, i8* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %3
%11 = call i32 @strncpy(i8* %0, i8* %6, i64 %1)
%12 = load i64, i64* %5
%13 = icmp ugt i64 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %10, %14, %3
%20 = phi i32 [ 0, %3 ], [ 1, %14 ], [ 1, %10 ]
ret i32 %20
}