#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 */
typedef int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ *PI_Py_DecodeLocale(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pyi_global_printf(char *, ...);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
char *strdup(int /*<<< orphan*/);
wchar_t **pyi_wargv_from_argv(int argc, char **argv) {
  wchar_t **wargv;
  char *oldloc;
  int i;
  oldloc = strdup(setlocale(LC_CTYPE, NULL));
  if (!oldloc) {
    pyi_global_printf("out of memory\n");
    return NULL;
  }
  wargv = (wchar_t **)malloc(sizeof(wchar_t *) * (argc + 1));
  if (!wargv) {
    pyi_global_printf("out of memory\n");
    return NULL;
  }
  setlocale(LC_CTYPE, "");
  for (i = 0; i < argc; i++) {
    wargv[i] = PI_Py_DecodeLocale(argv[i], NULL);
    if (!wargv[i]) {
      free(oldloc);
      pyi_global_printf("Fatal error: "
                        "unable to decode the command line argument #%i\n",
                        i + 1);
      return NULL;
    }
  }
  wargv[argc] = NULL;
  setlocale(LC_CTYPE, oldloc);
  free(oldloc);
  return wargv;
}


x86 assembly (clang, -O0):
<pyi_wargv_from_argv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setlocale@plt>
mov    %eax,%edi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <pyi_wargv_from_argv+0x52>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <pyi_global_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12be <pyi_wargv_from_argv+0x15e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ef <pyi_wargv_from_argv+0x8f>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <pyi_global_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12be <pyi_wargv_from_argv+0x15e>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1060 <setlocale@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    128b <pyi_wargv_from_argv+0x12b>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <PI_Py_DecodeLocale@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1278 <pyi_wargv_from_argv+0x118>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <pyi_global_printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12be <pyi_wargv_from_argv+0x15e>
jmp    127d <pyi_wargv_from_argv+0x11d>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120b <pyi_wargv_from_argv+0xab>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
call   1060 <setlocale@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pyi_wargv_from_argv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x2e70(%rip),%rbx
mov    (%rbx),%edi
xor    %esi,%esi
call   1060 <setlocale@plt>
mov    %eax,%edi
call   1080 <strdup@plt>
test   %rax,%rax
je     1205 <pyi_wargv_from_argv+0xa5>
mov    %rax,%r12
lea    0x8(,%r14,8),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1205 <pyi_wargv_from_argv+0xa5>
mov    %rax,%r13
mov    (%rbx),%edi
lea    0xe9d(%rip),%rsi
call   1060 <setlocale@plt>
test   %r14d,%r14d
jle    11de <pyi_wargv_from_argv+0x7e>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,8),%rdi
xor    %esi,%esi
call   1070 <PI_Py_DecodeLocale@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
je     1228 <pyi_wargv_from_argv+0xc8>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11c0 <pyi_wargv_from_argv+0x60>
movslq %r14d,%rax
movq   $0x0,0x0(%r13,%rax,8)
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1060 <setlocale@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1216 <pyi_wargv_from_argv+0xb6>
lea    0xdf4(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1040 <pyi_global_printf@plt>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x1,%ebx
lea    0xdd5(%rip),%rdi
xor    %r13d,%r13d
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <pyi_global_printf@plt>
jmp    1216 <pyi_wargv_from_argv+0xb6>

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [61 x i8] c"Fatal error: unable to decode the command line argument #%i\0A\00"
define i32** @pyi_wargv_from_argv(i32 %0, i8** %1) {
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32**
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @LC_CTYPE
%10 = call i32 @setlocale(i32 %9, i8* null)
%11 = call i8* @strdup(i32 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 (i8*, ...) @pyi_global_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32** null, i32*** %3
br label %73
16: ; preds = %2
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 8, %19
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i32**
store i32** %23, i32*** %6
%24 = load i32**, i32*** %6
%25 = icmp ne i32** %24, null
br i1 %25, label %28, label %26
26: ; preds = %16
%27 = call i32 (i8*, ...) @pyi_global_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32** null, i32*** %3
br label %73
28: ; preds = %16
%29 = load i32, i32* @LC_CTYPE
%30 = call i32 @setlocale(i32 %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %31
31: ; preds = %59, %28
%32 = load i32, i32* %8
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %62
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
%40 = load i8*, i8** %39
%41 = call i32* @PI_Py_DecodeLocale(i8* %40, i32* null)
%42 = load i32**, i32*** %6
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32*, i32** %42, i64 %44
store i32* %41, i32** %45
%46 = load i32**, i32*** %6
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32*, i32** %46, i64 %48
%50 = load i32*, i32** %49
%51 = icmp ne i32* %50, null
br i1 %51, label %58, label %52
52: ; preds = %35
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
%57 = call i32 (i8*, ...) @pyi_global_printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %56)
store i32** null, i32*** %3
br label %73
58: ; preds = %35
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %31
62: ; preds = %31
%63 = load i32**, i32*** %6
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32*, i32** %63, i64 %65
store i32* null, i32** %66
%67 = load i32, i32* @LC_CTYPE
%68 = load i8*, i8** %7
%69 = call i32 @setlocale(i32 %67, i8* %68)
%70 = load i8*, i8** %7
%71 = call i32 @free(i8* %70)
%72 = load i32**, i32*** %6
store i32** %72, i32*** %3
br label %73
73: ; preds = %62, %52, %26, %14
%74 = load i32**, i32*** %3
ret i32** %74
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [61 x i8] c"Fatal error: unable to decode the command line argument #%i\0A\00"
define i32** @pyi_wargv_from_argv(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @LC_CTYPE
%4 = tail call i32 @setlocale(i32 %3, i8* null)
%5 = tail call i8* @strdup(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @pyi_global_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %44
9: ; preds = %2
%10 = shl i32 %0, 3
%11 = add i32 %10, 8
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32**
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 (i8*, ...) @pyi_global_printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %44
17: ; preds = %9
%18 = load i32, i32* @LC_CTYPE
%19 = tail call i32 @setlocale(i32 %18, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp sgt i32 %0, 0
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = zext i32 %0 to i64
br label %23
23: ; preds = %21, %35
%24 = phi i64 [ 0, %21 ], [ %36, %35 ]
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32* @PI_Py_DecodeLocale(i8* %26, i32* null)
%28 = getelementptr inbounds i32*, i32** %13, i64 %24
store i32* %27, i32** %28
%29 = icmp eq i32* %27, null
br i1 %29, label %30, label %35
30: ; preds = %23
%31 = trunc i64 %24 to i32
%32 = tail call i32 @free(i8* %5)
%33 = add nuw nsw i32 %31, 1
%34 = tail call i32 (i8*, ...) @pyi_global_printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %44
35: ; preds = %23
%36 = add nuw nsw i64 %24, 1
%37 = icmp eq i64 %36, %22
br i1 %37, label %38, label %23
38: ; preds = %35, %17
%39 = sext i32 %0 to i64
%40 = getelementptr inbounds i32*, i32** %13, i64 %39
store i32* null, i32** %40
%41 = load i32, i32* @LC_CTYPE
%42 = tail call i32 @setlocale(i32 %41, i8* %5)
%43 = tail call i32 @free(i8* %5)
br label %44
44: ; preds = %38, %30, %15, %7
%45 = phi i32** [ null, %30 ], [ %13, %38 ], [ null, %15 ], [ null, %7 ]
ret i32** %45
}