#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 rand();
int /*<<< orphan*/ sprintf(char *, char *, ...);
void create_extension_pattern(char *buf, const char *name) {
  int i, extension;
  extension = rand() % (128 + 1);
  buf += sprintf(buf, ":%s:E::", name);
  for (i = 0; i < extension; i++) {
    int c = rand();
    if (c == '\0' || c == ':' || c == '\n' || c == '/')
      c = '1';
    buf += sprintf(buf, "%c", c);
  }
  sprintf(buf, "::/bin/bash:");
}


x86 assembly (clang, -O0):
<create_extension_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x81,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeaf(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e7 <create_extension_pattern+0xc7>
mov    $0x0,%al
call   1040 <rand@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11ad <create_extension_pattern+0x8d>
cmpl   $0x3a,-0x1c(%rbp)
je     11ad <create_extension_pattern+0x8d>
cmpl   $0xa,-0x1c(%rbp)
je     11ad <create_extension_pattern+0x8d>
cmpl   $0x2f,-0x1c(%rbp)
jne    11b4 <create_extension_pattern+0x94>
movl   $0x31,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116f <create_extension_pattern+0x4f>
mov    -0x8(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_extension_pattern>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%r12
imul   $0xfe03f81,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
add    %eax,%ecx
sub    %ecx,%r12d
lea    0xea3(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <sprintf@plt>
movslq %eax,%rbx
add    %r15,%rbx
test   %r12d,%r12d
jle    11b0 <create_extension_pattern+0x90>
mov    $0x31,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cmp    $0x3a,%eax
mov    %eax,%ecx
cmove  %ebp,%ecx
test   %eax,%eax
cmove  %ebp,%ecx
cmp    $0xa,%eax
cmove  %ebp,%ecx
cmp    $0x2f,%eax
cmove  %ebp,%ecx
mov    %cl,(%rbx)
movb   $0x0,0x1(%rbx)
add    $0x1,%rbx
add    $0xffffffff,%r12d
jne    1180 <create_extension_pattern+0x60>
movabs $0x3a687361622f6e,%rax
mov    %rax,0x5(%rbx)
movabs $0x622f6e69622f3a3a,%rax
6e 2f 62
mov    %rax,(%rbx)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c":%s:E::\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [13 x i8] c"::/bin/bash:\00"
define void @create_extension_pattern(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 129
store i32 %9, i32* %6
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %3
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i8, i8* %13, i64 %14
store i8* %15, i8** %3
store i32 0, i32* %5
br label %16
16: ; preds = %41, %2
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = call i32 (...) @rand()
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %20
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 58
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 10
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %34
33: ; preds = %30, %27, %24, %20
store i32 49, i32* %7
br label %34
34: ; preds = %33, %30
%35 = load i8*, i8** %3
%36 = load i32, i32* %7
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = load i8*, i8** %3
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %3
br label %41
41: ; preds = %34
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %16
44: ; preds = %16
%45 = load i8*, i8** %3
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c":%s:E::\00"
@.str.2 = [13 x i8] c"::/bin/bash:\00"
define void @create_extension_pattern(i8* nocapture writeonly %0, i8* %1) {
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 129
%5 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %25
9: ; preds = %2, %9
%10 = phi i8* [ %22, %9 ], [ %7, %2 ]
%11 = phi i32 [ %23, %9 ], [ 0, %2 ]
%12 = tail call i32 (...) @rand()
%13 = icmp eq i32 %12, 0
%14 = icmp eq i32 %12, 58
%15 = or i1 %13, %14
%16 = icmp eq i32 %12, 10
%17 = or i1 %16, %15
%18 = icmp eq i32 %12, 47
%19 = or i1 %18, %17
%20 = trunc i32 %12 to i8
%21 = select i1 %19, i8 49, i8 %20
store i8 %21, i8* %10
%22 = getelementptr i8, i8* %10, i64 1
store i8 0, i8* %22
%23 = add nuw nsw i32 %11, 1
%24 = icmp eq i32 %23, %4
br i1 %24, label %25, label %9
25: ; preds = %9, %2
%26 = phi i8* [ %7, %2 ], [ %22, %9 ]
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(13) %26, i8* align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 13, i1 false)
ret void
}