#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen_(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int /*<<< orphan*/);
int main() {
  char dest[30];
  char *a = "The c programming ";
  char *b = "language";
  char *c = "age.";
  char *d = "lbng...";
  strncpy(dest, a, strlen_(a));
  printf("strncpy : %s\n", dest);
  strncat(dest, b, 5);
  printf("strncat : %s\n", dest);
  strncat(dest, c, 4);
  printf("strncat : %s\n", dest);
  printf("strncmp : %d\n", strncmp(b, d, 4));
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xea2(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xea0(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <strlen_@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x5,%edx
call   1060 <strncat@plt>
lea    -0x30(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0x4,%edx
call   1060 <strncat@plt>
lea    -0x30(%rbp),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xea0(%rip),%r14
mov    %r14,%rdi
call   1070 <strlen_@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    0xeaa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe83(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1060 <strncat@plt>
lea    0xe90(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1060 <strncat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe45(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"The c programming \00"
@.str.1 = [9 x i8] c"language\00"
@.str.2 = [5 x i8] c"age.\00"
@.str.3 = [8 x i8] c"lbng...\00"
@.str.4 = [14 x i8] c"strncpy : %s\0A\00"
@.str.5 = [14 x i8] c"strncat : %s\0A\00"
@.str.6 = [14 x i8] c"strncmp : %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen_(i8* %9)
%11 = call i32 @strncpy(i8* %7, i8* %8, i32 %10)
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = call i32 @strncat(i8* %14, i8* %15, i32 5)
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = call i32 @strncat(i8* %19, i8* %20, i32 4)
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %4
%25 = load i8*, i8** %6
%26 = call i32 @strncmp(i8* %24, i8* %25, i32 4)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_SUCCESS
ret i32 %28
}

LLVM IR (-O2):
@.str = [19 x i8] c"The c programming \00"
@.str.1 = [9 x i8] c"language\00"
@.str.2 = [5 x i8] c"age.\00"
@.str.3 = [8 x i8] c"lbng...\00"
@.str.4 = [14 x i8] c"strncpy : %s\0A\00"
@.str.5 = [14 x i8] c"strncat : %s\0A\00"
@.str.6 = [14 x i8] c"strncmp : %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @strlen_(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %2)
%6 = call i32 @strncat(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 5)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%8 = call i32 @strncat(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %2)
%10 = call i32 @strncmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 4)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @EXIT_SUCCESS
ret i32 %12
}