#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *);
scalar_t__ strlen(char *);
void clear_cmdline(int argc, char **argv) {
  int len = 0;
  int i;
  for (i = 0; i < argc; i++) {
    len += strlen(argv[i]) + 1;
  }
  memset(argv[0], 0, len);
  snprintf(argv[0], len, "bnac");
}


x86 assembly (clang, -O0):
<clear_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1189 <clear_cmdline+0x59>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114d <clear_cmdline+0x1d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
lea    0xe55(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_cmdline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %edi,%edi
jle    116b <clear_cmdline+0x3b>
mov    %edi,%r15d
xor    %ebx,%ebx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
call   1030 <strlen@plt>
add    %eax,%r12d
add    $0x1,%r12d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <clear_cmdline+0x20>
jmp    116e <clear_cmdline+0x3e>
xor    %r12d,%r12d
mov    (%r14),%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1050 <memset@plt>
mov    (%r14),%rdi
lea    0xe7b(%rip),%rdx
mov    %r12d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <snprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"bnac\00"
define void @clear_cmdline(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %23, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i8**, i8*** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = add nsw i64 %20, %18
%22 = trunc i64 %21 to i32
store i32 %22, i32* %5
br label %23
23: ; preds = %11
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %7
26: ; preds = %7
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i32, i32* %5
%31 = call i32 @memset(i8* %29, i32 0, i32 %30)
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = load i32, i32* %5
%36 = call i32 @snprintf(i8* %34, i32 %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"bnac\00"
define void @clear_cmdline(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %15, %6 ]
%8 = phi i32 [ 0, %4 ], [ %14, %6 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %7
%10 = load i8*, i8** %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = trunc i64 %11 to i32
%13 = add i32 %8, 1
%14 = add i32 %13, %12
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %6
17: ; preds = %6, %2
%18 = phi i32 [ 0, %2 ], [ %14, %6 ]
%19 = load i8*, i8** %1
%20 = tail call i32 @memset(i8* %19, i32 0, i32 %18)
%21 = load i8*, i8** %1
%22 = tail call i32 @snprintf(i8* %21, i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret void
}