#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 rand();
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int copy_passwd(char *passwd, int argn, char **argv) {
  char i, def[] = "default";
  i = rand() % 100;
  if (argn == 1)
    strcpy(passwd, def);
  if (argn >= 2) {
    strncpy(passwd, argv[1], 11);
    passwd[11] = 0;
  }
  if (argn == 3 && !atoi(argv[2]))
    i = atoi(argv[2]) % 100;
  return i;
}


x86 assembly (clang, -O0):
<copy_passwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xea6(%rip),%rax
mov    %rax,-0x21(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x19(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1189 <copy_passwd+0x49>
mov    -0x8(%rbp),%rdi
lea    -0x21(%rbp),%rsi
call   1040 <strcpy@plt>
cmpl   $0x2,-0xc(%rbp)
jl     11b1 <copy_passwd+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0xb(%rax)
cmpl   $0x3,-0xc(%rbp)
jne    11eb <copy_passwd+0xab>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
cmp    $0x0,%eax
jne    11eb <copy_passwd+0xab>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_passwd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
movabs $0x746c7561666564,%rax
mov    %rax,(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
movslq %eax,%rbx
imul   $0x51eb851f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%ebx
cmp    $0x1,%ebp
jne    1192 <copy_passwd+0x52>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
jmp    11bd <copy_passwd+0x7d>
jle    11bd <copy_passwd+0x7d>
mov    0x8(%r14),%rsi
mov    %r15,%rdi
mov    $0xb,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xb(%r15)
cmp    $0x3,%ebp
jne    11bd <copy_passwd+0x7d>
mov    0x10(%r14),%rdi
call   1050 <atoi@plt>
test   %eax,%eax
cmove  %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.copy_passwd.def = [8 x i8] c"default\00"
define i32 @copy_passwd(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8
%8 = alloca [8 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%9 = bitcast [8 x i8]* %8 to i8*
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = trunc i32 %11 to i8
store i8 %12, i8* %7
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %4
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%18 = call i32 @strcpy(i8* %16, i8* %17)
br label %19
19: ; preds = %15, %3
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 2
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = load i8**, i8*** %6
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strncpy(i8* %23, i8* %26, i32 11)
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 11
store i8 0, i8* %29
br label %30
30: ; preds = %22, %19
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, 3
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i8**, i8*** %6
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %46, label %39
39: ; preds = %33
%40 = load i8**, i8*** %6
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = srem i32 %43, 100
%45 = trunc i32 %44 to i8
store i8 %45, i8* %7
br label %46
46: ; preds = %39, %33, %30
%47 = load i8, i8* %7
%48 = sext i8 %47 to i32
ret i32 %48
}

LLVM IR (-O2):
define i32 @copy_passwd(i8* %0, i32 %1, i8** nocapture %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
store i64 32770348699510116, i64* %4
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 100
%8 = icmp eq i32 %1, 1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @strcpy(i8* %0, i8* %5)
br label %25
11: ; preds = %3
%12 = icmp sgt i32 %1, 1
br i1 %12, label %13, label %25
13: ; preds = %11
%14 = getelementptr inbounds i8*, i8** %2, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @strncpy(i8* %0, i8* %15, i32 11)
%17 = getelementptr inbounds i8, i8* %0, i64 11
store i8 0, i8* %17
%18 = icmp eq i32 %1, 3
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = getelementptr inbounds i8*, i8** %2, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i32 0, i32 %7
br label %25
25: ; preds = %11, %9, %19, %13
%26 = phi i32 [ %7, %13 ], [ %24, %19 ], [ %7, %9 ], [ %7, %11 ]
ret i32 %26
}