#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 */
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ dest4;
typedef int /*<<< orphan*/ dest3;
typedef int /*<<< orphan*/ dest2;
typedef int /*<<< orphan*/ dest1;

/* Variables and functions */
int /*<<< orphan*/ cp(char *, char *, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ ncp(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char src[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
  char dest1[8] = {0};
  char dest2[9] = {0};
  char dest3[8] = {0};
  char dest4[9] = {0};
  {
    struct timeval start1;
    struct timeval stop1;
    gettimeofday(&start1, NULL);
    for (int i = 0; i < 1000000; ++i) {
      ncp(dest3, src, sizeof(dest3) - 1);
      ncp(dest4, src, sizeof(dest4) - 1);
    }
    gettimeofday(&stop1, NULL);
    printf("%s\n", dest3);
    printf("%s\n", dest4);
    printf("norm eslapse: %ld s %ld us\n", stop1.tv_sec - start1.tv_sec,
           stop1.tv_usec - start1.tv_usec);
  }
  struct timeval start;
  struct timeval stop;
  gettimeofday(&start, NULL);
  for (int i = 0; i < 1000000; ++i) {
    cp(dest1, src, sizeof(dest1) - 1);
    cp(dest2, src, sizeof(dest2) - 1);
  }
  gettimeofday(&stop, NULL);
  printf("%s\n", dest2);
  printf("%s\n", dest1);
  printf("duffs device eslapse: %ld s %ld us\n", stop.tv_sec - start.tv_sec,
         stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe8d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe8b(%rip),%eax
mov    %eax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x41(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1060 <memset@plt>
lea    -0x49(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x52(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1060 <memset@plt>
lea    -0x68(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x7c(%rbp)
cmpl   $0xf4240,-0x7c(%rbp)
jge    121b <main+0xcb>
lea    -0x49(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x7,%edx
call   1070 <ncp@plt>
lea    -0x52(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1070 <ncp@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11dc <main+0x8c>
lea    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x49(%rbp),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x52(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x70(%rbp),%esi
sub    -0x60(%rbp),%esi
mov    -0x78(%rbp),%rdx
sub    -0x68(%rbp),%rdx
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0xa4(%rbp)
cmpl   $0xf4240,-0xa4(%rbp)
jge    12ca <main+0x17a>
lea    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x7,%edx
call   1030 <cp@plt>
lea    -0x41(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1030 <cp@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1282 <main+0x132>
lea    -0xa0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x41(%rbp),%rsi
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x38(%rbp),%rsi
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x98(%rbp),%esi
sub    -0x88(%rbp),%esi
mov    -0xa0(%rbp),%rdx
sub    -0x90(%rbp),%rdx
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movl   $0x30393837,0x60(%rsp)
30
movq   $0x0,0x48(%rsp)
movb   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x40(%rsp)
movb   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    $0xf4240,%ebp
lea    0x40(%rsp),%r14
lea    0x50(%rsp),%rbx
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1070 <ncp@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1070 <ncp@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x70>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0x40(%rsp),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1030 <puts@plt>
mov    0x28(%rsp),%esi
sub    0x38(%rsp),%esi
mov    0x20(%rsp),%rdx
sub    0x30(%rsp),%rdx
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    $0xf4240,%ebp
lea    0x48(%rsp),%r14
lea    0x50(%rsp),%rbx
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1040 <cp@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <cp@plt>
add    $0xffffffff,%ebp
jne    1250 <main+0x100>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
lea    0x48(%rsp),%rdi
call   1030 <puts@plt>
mov    0x28(%rsp),%esi
sub    0x38(%rsp),%esi
mov    0x20(%rsp),%rdx
sub    0x30(%rsp),%rdx
lea    0xd82(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
@__const.main.src = [20 x i8] c"12345678901234567890"
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [28 x i8] c"norm eslapse: %ld s %ld us\0A\00"
@.str.2 = [36 x i8] c"duffs device eslapse: %ld s %ld us\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca [8 x i8]
%8 = alloca [9 x i8]
%9 = alloca [8 x i8]
%10 = alloca [9 x i8]
%11 = alloca %struct.timeval
%12 = alloca %struct.timeval
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca %struct.timeval
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [20 x i8]* %6 to i8*
%18 = bitcast [8 x i8]* %7 to i8*
%19 = bitcast [9 x i8]* %8 to i8*
%20 = bitcast [8 x i8]* %9 to i8*
%21 = bitcast [9 x i8]* %10 to i8*
%22 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
store i32 0, i32* %13
br label %23
23: ; preds = %33, %2
%24 = load i32, i32* %13
%25 = icmp slt i32 %24, 1000000
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%29 = call i32 @ncp(i8* %27, i8* %28, i32 7)
%30 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%32 = call i32 @ncp(i8* %30, i8* %31, i32 8)
br label %33
33: ; preds = %26
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 1
store i32 %35, i32* %13
br label %23
36: ; preds = %23
%37 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%45 = load i32, i32* %44
%46 = sub nsw i32 %43, %45
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%50 = load i64, i64* %49
%51 = sub nsw i64 %48, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %46, i64 %51)
%53 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
store i32 0, i32* %16
br label %54
54: ; preds = %64, %36
%55 = load i32, i32* %16
%56 = icmp slt i32 %55, 1000000
br i1 %56, label %57, label %67
57: ; preds = %54
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%59 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%60 = call i32 @cp(i8* %58, i8* %59, i32 7)
%61 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%62 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%63 = call i32 @cp(i8* %61, i8* %62, i32 8)
br label %64
64: ; preds = %57
%65 = load i32, i32* %16
%66 = add nsw i32 %65, 1
store i32 %66, i32* %16
br label %54
67: ; preds = %54
%68 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%69 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %69)
%71 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %71)
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%74 = load i32, i32* %73
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%76 = load i32, i32* %75
%77 = sub nsw i32 %74, %76
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%79 = load i64, i64* %78
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%81 = load i64, i64* %80
%82 = sub nsw i64 %79, %81
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %77, i64 %82)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
@__const.main.src = [20 x i8] c"12345678901234567890"
@.str.1 = [28 x i8] c"norm eslapse: %ld s %ld us\0A\00"
@.str.2 = [36 x i8] c"duffs device eslapse: %ld s %ld us\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [20 x i8]
%4 = alloca i64
%5 = alloca [9 x i8]
%6 = alloca i64
%7 = alloca [9 x i8]
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%13 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%15 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %7, i64 0, i64 0
%17 = bitcast %struct.timeval* %8 to i8*
%18 = bitcast %struct.timeval* %9 to i8*
%19 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
br label %38
20: ; preds = %38
%21 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%22 = call i32 @puts(i8* %15)
%23 = call i32 @puts(i8* %16)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
%27 = load i32, i32* %26
%28 = sub nsw i32 %25, %27
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i64 0, i32 0
%30 = load i64, i64* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%32 = load i64, i64* %31
%33 = sub nsw i64 %30, %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %28, i64 %33)
%35 = bitcast %struct.timeval* %10 to i8*
%36 = bitcast %struct.timeval* %11 to i8*
%37 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
br label %59
38: ; preds = %2, %38
%39 = phi i32 [ 0, %2 ], [ %42, %38 ]
%40 = call i32 @ncp(i8* %15, i8* %12, i32 7)
%41 = call i32 @ncp(i8* %16, i8* %12, i32 8)
%42 = add nuw nsw i32 %39, 1
%43 = icmp eq i32 %42, 1000000
br i1 %43, label %20, label %38
44: ; preds = %59
%45 = call i32 @gettimeofday(%struct.timeval* %11, i32* null)
%46 = call i32 @puts(i8* %14)
%47 = call i32 @puts(i8* %13)
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i64 0, i32 1
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 1
%51 = load i32, i32* %50
%52 = sub nsw i32 %49, %51
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i64 0, i32 0
%54 = load i64, i64* %53
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i64 0, i32 0
%56 = load i64, i64* %55
%57 = sub nsw i64 %54, %56
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %52, i64 %57)
ret i32 0
59: ; preds = %20, %59
%60 = phi i32 [ 0, %20 ], [ %63, %59 ]
%61 = call i32 @cp(i8* %13, i8* %12, i32 7)
%62 = call i32 @cp(i8* %14, i8* %12, i32 8)
%63 = add nuw nsw i32 %60, 1
%64 = icmp eq i32 %63, 1000000
br i1 %64, label %44, label %59
}