#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 /*<<< orphan*/ strncat(char *, char *, size_t const);
int strncmp(char *, char *, size_t const);
int /*<<< orphan*/ strncpy(char *, char *, size_t const);
int main() {
  const size_t MAX = 100;
  char a[MAX];
  strncpy(a, "strncpy works!\n", MAX);
  strncat(a, "strncat works too!\n", MAX);
  printf("%s", a);
  char *b = "hello world";
  char *c = "hello zorld";
  printf("strncmp returned %d\n", strncmp(b, c, MAX));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x64,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x64,%edx
call   1060 <strncat@plt>
lea    0xe8c(%rip),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe7a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe7b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x64,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xec4(%rip),%rsi
mov    %rsp,%rbx
mov    $0x64,%edx
mov    %rbx,%rdi
call   1030 <strncpy@plt>
lea    0xebd(%rip),%rsi
mov    $0x64,%edx
mov    %rbx,%rdi
call   1050 <strncat@plt>
lea    0xebd(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaf(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"strncpy works!\0A\00"
@.str.1 = [20 x i8] c"strncat works too!\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c"hello world\00"
@.str.4 = [12 x i8] c"hello zorld\00"
@.str.5 = [21 x i8] c"strncmp returned %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i64 100, i64* %2
%6 = call i8* @llvm.stacksave()
store i8* %6, i8** %3
%7 = alloca i8, i64 100
%8 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 100)
%9 = call i32 @strncat(i8* %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 100)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8** %5
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i32 @strncmp(i8* %11, i8* %12, i64 100)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %13)
store i32 0, i32* %1
%15 = load i8*, i8** %3
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@.str = [16 x i8] c"strncpy works!\0A\00"
@.str.1 = [20 x i8] c"strncat works too!\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.5 = [21 x i8] c"strncmp returned %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64 100)
%4 = call i32 @strncat(i8* %2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64 100)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 -1)
ret i32 0
}