#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 *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ usage(int, char **);
int main(int argc, char *argv[]) {
  usage(argc, argv);
  int val = 5;
  char buf1[8], buf2[8];
  strcpy(buf1, "one");
  strcpy(buf2, "two");
  printf("[before] buf2@%p contains '%s'\n", buf2, buf2);
  printf("[before] buf1@%p contains '%s'\n", buf1, buf1);
  printf("[before] val@%p contains %d (0x%08x)\n", &val, val, val);
  printf("[strcpy] %d bytes -> buf2\n", strlen(argv[1]));
  strcpy(buf2, argv[1]);
  printf("[after] buf2@%p contains '%s'\n", buf2, buf2);
  printf("[after] buf1@%p contains '%s'\n", buf1, buf1);
  printf("[after] val@%p contains %d (0x%08x)\n", &val, val, val);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <usage@plt>
movl   $0x5,-0x14(%rbp)
lea    -0x1c(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x24(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x24(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1c(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe8d(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x24(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x24(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x1c(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe9a(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
call   1060 <usage@plt>
movl   $0x5,0x4(%rsp)
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe8e(%rip),%rsi
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe7e(%rip),%rdi
mov    %r15,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    %r14,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe96(%rip),%rdi
lea    0x4(%rsp),%r12
mov    %r12,%rsi
mov    $0x5,%edx
mov    $0x5,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
call   1040 <strlen@plt>
lea    0xe93(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe92(%rip),%rdi
mov    %r15,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    %r14,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%ecx
lea    0xea4(%rip),%rdi
mov    %r12,%rsi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"one\00"
@.str.1 = [4 x i8] c"two\00"
@.str.2 = [32 x i8] c"[before] buf2@%p contains '%s'\0A\00"
@.str.3 = [32 x i8] c"[before] buf1@%p contains '%s'\0A\00"
@.str.4 = [38 x i8] c"[before] val@%p contains %d (0x%08x)\0A\00"
@.str.5 = [27 x i8] c"[strcpy] %d bytes -> buf2\0A\00"
@.str.6 = [31 x i8] c"[after] buf2@%p contains '%s'\0A\00"
@.str.7 = [31 x i8] c"[after] buf1@%p contains '%s'\0A\00"
@.str.8 = [37 x i8] c"[after] val@%p contains %d (0x%08x)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca [8 x i8]
%7 = alloca [8 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = load i8**, i8*** %4
%10 = call i32 @usage(i32 %8, i8** %9)
store i32 5, i32* %5
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %16)
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i32, i32* %5
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32* %5, i32 %21, i32 %22)
%24 = load i8**, i8*** %4
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcpy(i8* %29, i8* %32)
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %34, i8* %35)
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i32, i32* %5
%41 = load i32, i32* %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i32* %5, i32 %40, i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"one\00"
@.str.1 = [4 x i8] c"two\00"
@.str.2 = [32 x i8] c"[before] buf2@%p contains '%s'\0A\00"
@.str.3 = [32 x i8] c"[before] buf1@%p contains '%s'\0A\00"
@.str.4 = [38 x i8] c"[before] val@%p contains %d (0x%08x)\0A\00"
@.str.5 = [27 x i8] c"[strcpy] %d bytes -> buf2\0A\00"
@.str.6 = [31 x i8] c"[after] buf2@%p contains '%s'\0A\00"
@.str.7 = [31 x i8] c"[after] buf1@%p contains '%s'\0A\00"
@.str.8 = [37 x i8] c"[after] val@%p contains %d (0x%08x)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca [8 x i8]
%6 = tail call i32 @usage(i32 %0, i8** %1)
%7 = bitcast i32* %3 to i8*
store i32 5, i32* %3
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%10 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %9)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %8, i8* %8)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32 5, i32 5)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strlen(i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %15
%20 = call i32 @strcpy(i8* %9, i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %9, i8* %9)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %8, i8* %8)
%23 = load i32, i32* %3
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i32* %3, i32 %23, i32 %23)
ret i32 0
}