#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 atoi(char *);
int /*<<< orphan*/ memcpy(char *, char *, unsigned short);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  unsigned short s;
  int i;
  char buf[80];
  if (argc < 3) {
    printf("there needs 2 args");
    return -1;
  }
  i = atoi(argv[1]);
  s = i;
  if (s >= 80) {
    printf("oh no !\n");
  }
  printf("s = %d\n", s);
  memcpy(buf, argv[2], s);
  printf("i = %d\n", i);
  buf[s] = '\0';
  printf("the string is :%s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%eax
cmp    $0x50,%eax
jl     119c <main+0x6c>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x12(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x12(%rbp),%ax
movzwl %ax,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x12(%rbp),%eax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
cmp    $0x2,%edi
jg     1164 <main+0x24>
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    11d3 <main+0x93>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
movzwl %r14w,%ebx
cmp    $0x50,%ebx
jb     1188 <main+0x48>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xe84(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r15),%rsi
movzwl %r14w,%edx
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <memcpy@plt>
lea    0xe67(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x0,(%rsp,%rbx,1)
lea    0xe5a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"there needs 2 args\00"
@.str.1 = [9 x i8] c"oh no !\0A\00"
@.str.2 = [8 x i8] c"s = %d\0A\00"
@.str.3 = [8 x i8] c"i = %d\0A\00"
@.str.4 = [19 x i8] c"the string is :%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32
%8 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = trunc i32 %18 to i16
store i16 %19, i16* %6
%20 = load i16, i16* %6
%21 = zext i16 %20 to i32
%22 = icmp sge i32 %21, 80
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
%26 = load i16, i16* %6
%27 = zext i16 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = load i16, i16* %6
%34 = call i32 @memcpy(i8* %29, i8* %32, i16 zeroext %33)
%35 = load i32, i32* %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i16, i16* %6
%38 = zext i16 %37 to i64
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %25, %11
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [19 x i8] c"there needs 2 args\00"
@.str.2 = [8 x i8] c"s = %d\0A\00"
@.str.3 = [8 x i8] c"i = %d\0A\00"
@.str.4 = [19 x i8] c"the string is :%s\0A\00"
@str = [8 x i8] c"oh no !\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %26
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = trunc i32 %11 to i16
%13 = and i32 %11, 65535
%14 = icmp ugt i32 %13, 79
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @memcpy(i8* %4, i8* %20, i16 zeroext %12)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%23 = zext i32 %13 to i64
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %23
store i8 0, i8* %24
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %26
26: ; preds = %17, %6
%27 = phi i32 [ -1, %6 ], [ 0, %17 ]
ret i32 %27
}