#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 atol(char *);
int ncopy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int main(int argc, char **argv) {
  char *s = argc > 1 ? argv[1] : argv[0];
  int n = argc < 2 ? 5 : atol(argv[2]);
  char buf[0x100];
  int res = ncopy(s, buf, n);
  printf("%s res=%d\n", buf, res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1167 <main+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x130(%rbp)
jmp    1175 <main+0x45>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119a <main+0x6a>
mov    $0x5,%eax
mov    %eax,-0x134(%rbp)
jmp    11ad <main+0x7d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <atol@plt>
mov    %eax,-0x134(%rbp)
mov    -0x134(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <ncopy@plt>
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
mov    $0x5,%edx
cmp    $0x2,%edi
setge  %al
mov    (%rsi,%rax,8),%rbx
jl     1158 <main+0x28>
mov    0x10(%rsi),%rdi
call   1040 <atol@plt>
mov    %eax,%edx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <ncopy@plt>
lea    0xe93(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"%s res=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp sgt i32 %0, 1
%5 = zext i1 %4 to i64
%6 = getelementptr i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = icmp slt i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atol(i8* %11)
br label %13
13: ; preds = %2, %9
%14 = phi i32 [ %12, %9 ], [ 5, %2 ]
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%16 = call i32 @ncopy(i8* %7, i8* %15, i32 %14)
%17 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
ret i32 0
}