#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*/ b;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncat(char *, char *, int);
int strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  char a[100] = "Hello";
  char b[] = ", world!";
  char c[sizeof(b)] = {0};
  strncpy(c, b, 7);
  printf("c: %s\n", c);
  strncat(a, c, 100);
  printf("a: %s\n", a);
  strncat(a, c, 3);
  printf("a: %s\n", a);
  printf("%d\n", strncmp(b, ", wor", 5));
  printf("%d\n", strncmp(b, ", wor", 500));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
movb   $0x48,-0x70(%rbp)
movb   $0x65,-0x6f(%rbp)
movb   $0x6c,-0x6e(%rbp)
movb   $0x6c,-0x6d(%rbp)
movb   $0x6f,-0x6c(%rbp)
mov    0xe73(%rip),%rax
mov    %rax,-0x79(%rbp)
mov    0xe71(%rip),%al
mov    %al,-0x71(%rbp)
lea    -0x82(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1060 <memset@plt>
lea    -0x82(%rbp),%rdi
lea    -0x79(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
lea    -0x82(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x82(%rbp),%rsi
mov    $0x64,%edx
call   1070 <strncat@plt>
lea    -0x70(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x82(%rbp),%rsi
mov    $0x3,%edx
call   1070 <strncat@plt>
lea    -0x70(%rbp),%rsi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x79(%rbp),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x79(%rbp),%rdi
lea    0xdc6(%rip),%rsi
mov    $0x1f4,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x80(%rsp)
movl   $0x6c6c6548,0x20(%rsp)
6c
movb   $0x6f,0x24(%rsp)
movabs $0x21646c726f77202c,%rax
6c 64 21
mov    %rax,0x10(%rsp)
movb   $0x0,0x18(%rsp)
movb   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%r15
lea    0x10(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
lea    0xe42(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x64,%edx
call   1060 <strncat@plt>
lea    0xe23(%rip),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1060 <strncat@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdfd(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
lea    0xde2(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1f4,%edx
call   1040 <strncmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.b = [9 x i8] c", world!\00"
@.str = [7 x i8] c"c: %s\0A\00"
@.str.1 = [7 x i8] c"a: %s\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [6 x i8] c", wor\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [9 x i8]
%4 = alloca [9 x i8]
store i32 0, i32* %1
%5 = bitcast [100 x i8]* %2 to i8*
%6 = bitcast i8* %5 to [100 x i8]*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 0
store i8 72, i8* %7
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 1
store i8 101, i8* %8
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 2
store i8 108, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 3
store i8 108, i8* %10
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i32 0, i32 4
store i8 111, i8* %11
%12 = bitcast [9 x i8]* %3 to i8*
%13 = bitcast [9 x i8]* %4 to i8*
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 7)
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%21 = call i32 @strncat(i8* %19, i8* %20, i32 100)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%26 = call i32 @strncat(i8* %24, i8* %25, i32 3)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%30 = call i32 @strncmp(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%33 = call i32 @strncmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 500)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
ret i32 0
}

LLVM IR (-O2):
@__const.main.b = [9 x i8] c", world!\00"
@.str = [7 x i8] c"c: %s\0A\00"
@.str.1 = [7 x i8] c"a: %s\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [6 x i8] c", wor\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [9 x i8]
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 72, i8* %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
store i8 101, i8* %5
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
store i8 108, i8* %6
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 108, i8* %7
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 4
store i8 111, i8* %8
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%11 = call i32 @strncpy(i8* %10, i8* %9, i32 7)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %10)
%13 = call i32 @strncat(i8* %4, i8* %10, i32 100)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%15 = call i32 @strncat(i8* %4, i8* %10, i32 3)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%17 = call i32 @strncmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = call i32 @strncmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 500)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
ret i32 0
}