#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*/ safe_strncpy(char *, char *, int);
int xstrlen(char *);
void fixup_argv(int argc, char **argv, char *new_argv0) {
  int len;
  len = xstrlen(argv[0]);
  memset(argv[0], 0, len);
  safe_strncpy(argv[0], new_argv0, len + 1);
  len = 1;
  while (argc > len) {
    memset(argv[len], 0, xstrlen(argv[len]));
    len++;
  }
}


x86 assembly (clang, -O0):
<fixup_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <xstrlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1040 <safe_strncpy@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11c8 <fixup_argv+0x98>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <xstrlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <fixup_argv+0x50>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixup_argv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %edi,%r15d
mov    (%rsi),%rdi
call   1050 <xstrlen@plt>
mov    %eax,%ebp
mov    (%r12),%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <memset@plt>
mov    (%r12),%rdi
add    $0x1,%ebp
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <safe_strncpy@plt>
cmp    $0x2,%r15d
jl     11a1 <fixup_argv+0x71>
mov    %r15d,%r14d
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rbp
mov    %rbp,%rdi
call   1050 <xstrlen@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <memset@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <fixup_argv+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fixup_argv(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 @xstrlen(i8* %10)
store i32 %11, i32* %7
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i32, i32* %7
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
%23 = call i32 @safe_strncpy(i8* %19, i8* %20, i32 %22)
store i32 1, i32* %7
br label %24
24: ; preds = %28, %3
%25 = load i32, i32* %4
%26 = load i32, i32* %7
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %43
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @xstrlen(i8* %38)
%40 = call i32 @memset(i8* %33, i32 0, i32 %39)
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %24
43: ; preds = %24
ret void
}

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