#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 *, char *, int);
int ncopy(char *s, char *t, int n) {
  printf("ss=%s n=%d\n", s, n);
  char *t0 = t;
  while (n > 0 && (*t = *s))
    s++, t++, n--;
  *t = 0;
  return t - t0;
}


x86 assembly (clang, -O0):
<ncopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xecf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jle    1165 <ncopy+0x55>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1175 <ncopy+0x65>
jmp    119b <ncopy+0x8b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <ncopy+0x2e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ncopy>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xedd(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rax
test   %ebp,%ebp
jle    1159 <ncopy+0x49>
add    $0x1,%ebp
mov    %r14,%rax
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%ecx
mov    %cl,(%rax)
test   %cl,%cl
je     1159 <ncopy+0x49>
add    $0x1,%rbx
add    $0x1,%rax
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     1140 <ncopy+0x30>
movb   $0x0,(%rax)
sub    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"ss=%s n=%d\0A\00"
define i32 @ncopy(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* %6
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
%11 = load i8*, i8** %5
store i8* %11, i8** %7
br label %12
12: ; preds = %23, %3
%13 = load i32, i32* %6
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = load i8*, i8** %5
store i8 %17, i8* %18
%19 = sext i8 %17 to i32
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %15, %12
%22 = phi i1 [ false, %12 ], [ %20, %15 ]
br i1 %22, label %23, label %30
23: ; preds = %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
br label %12
30: ; preds = %21
%31 = load i8*, i8** %5
store i8 0, i8* %31
%32 = load i8*, i8** %5
%33 = load i8*, i8** %7
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
ret i32 %37
}

LLVM IR (-O2):
@.str = [12 x i8] c"ss=%s n=%d\0A\00"
define i32 @ncopy(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %17
6: ; preds = %3, %12
%7 = phi i8* [ %13, %12 ], [ %0, %3 ]
%8 = phi i32 [ %15, %12 ], [ %2, %3 ]
%9 = phi i8* [ %14, %12 ], [ %1, %3 ]
%10 = load i8, i8* %7
store i8 %10, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = getelementptr inbounds i8, i8* %9, i64 1
%15 = add nsw i32 %8, -1
%16 = icmp sgt i32 %8, 1
br i1 %16, label %6, label %17
17: ; preds = %6, %12, %3
%18 = phi i8* [ %1, %3 ], [ %14, %12 ], [ %9, %6 ]
store i8 0, i8* %18
%19 = ptrtoint i8* %18 to i64
%20 = ptrtoint i8* %1 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
ret i32 %22
}