#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 */
struct extmod {
  int dummy;
};

/* Variables and functions */
char *basename(char *);
struct extmod *extmod_find(char *);
struct extmod *extmod_extract(int *argcp, char *argv[]) {
  struct extmod *module;
  char *execname;
  int argc = *argcp;
  int i;
  execname = basename(argv[0]);
  module = extmod_find(execname);
  if (!module && argc > 1) {
    module = extmod_find(argv[1]);
    if (module) {
      argc--;
      for (i = 1; i < argc; i++)
        argv[i] = argv[i + 1];
      *argcp = argc;
    }
  }
  return module;
}


x86 assembly (clang, -O0):
<extmod_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <basename@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <extmod_find@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dc <extmod_extract+0xbc>
cmpl   $0x1,-0x24(%rbp)
jle    11dc <extmod_extract+0xbc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <extmod_find@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d7 <extmod_extract+0xb7>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ce <extmod_extract+0xae>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1197 <extmod_extract+0x77>
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11dc <extmod_extract+0xbc>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extmod_extract>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rdi),%r12d
mov    (%rsi),%rdi
call   1030 <basename@plt>
mov    %rax,%rdi
call   1040 <extmod_find@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119d <extmod_extract+0x6d>
cmp    $0x2,%r12d
jl     119d <extmod_extract+0x6d>
mov    0x8(%r15),%rdi
call   1040 <extmod_find@plt>
test   %rax,%rax
je     119b <extmod_extract+0x6b>
mov    %rax,%rbx
lea    -0x1(%r12),%ebp
cmp    $0x3,%r12d
jb     1196 <extmod_extract+0x66>
lea    0x8(%r15),%rdi
add    $0x10,%r15
add    $0xfffffffe,%r12d
shl    $0x3,%r12
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <memmove@plt>
mov    %ebp,(%r14)
jmp    119d <extmod_extract+0x6d>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.extmod = type { i32 }
define %struct.extmod* @extmod_extract(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca %struct.extmod*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i8** %1, i8*** %4
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i8* @basename(i8* %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = call %struct.extmod* @extmod_find(i8* %15)
store %struct.extmod* %16, %struct.extmod** %5
%17 = load %struct.extmod*, %struct.extmod** %5
%18 = icmp ne %struct.extmod* %17, null
br i1 %18, label %54, label %19
19: ; preds = %2
%20 = load i32, i32* %7
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %54
22: ; preds = %19
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call %struct.extmod* @extmod_find(i8* %25)
store %struct.extmod* %26, %struct.extmod** %5
%27 = load %struct.extmod*, %struct.extmod** %5
%28 = icmp ne %struct.extmod* %27, null
br i1 %28, label %29, label %53
29: ; preds = %22
%30 = load i32, i32* %7
%31 = add nsw i32 %30, -1
store i32 %31, i32* %7
store i32 1, i32* %8
br label %32
32: ; preds = %47, %29
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %50
36: ; preds = %32
%37 = load i8**, i8*** %4
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %37, i64 %40
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %4
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
store i8* %42, i8** %46
br label %47
47: ; preds = %36
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %32
50: ; preds = %32
%51 = load i32, i32* %7
%52 = load i32*, i32** %3
store i32 %51, i32* %52
br label %53
53: ; preds = %50, %22
br label %54
54: ; preds = %53, %19, %2
%55 = load %struct.extmod*, %struct.extmod** %5
ret %struct.extmod* %55
}

LLVM IR (-O2):
%struct.extmod = type { i32 }
define %struct.extmod* @extmod_extract(i32* nocapture %0, i8** nocapture %1) {
%3 = load i32, i32* %0
%4 = load i8*, i8** %1
%5 = tail call i8* @basename(i8* %4)
%6 = tail call %struct.extmod* @extmod_find(i8* %5)
%7 = icmp eq %struct.extmod* %6, null
%8 = icmp sgt i32 %3, 1
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = getelementptr i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call %struct.extmod* @extmod_find(i8* %12)
%14 = icmp eq %struct.extmod* %13, null
br i1 %14, label %26, label %15
15: ; preds = %10
%16 = add nsw i32 %3, -1
%17 = icmp ugt i32 %3, 2
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = bitcast i8** %11 to i8*
%20 = getelementptr i8*, i8** %1, i64 2
%21 = bitcast i8** %20 to i8*
%22 = add nsw i32 %3, -2
%23 = zext i32 %22 to i64
%24 = shl nuw nsw i64 %23, 3
br label %25
25: ; preds = %18, %15
store i32 %16, i32* %0
br label %26
26: ; preds = %10, %25, %2
%27 = phi %struct.extmod* [ %13, %25 ], [ null, %10 ], [ %6, %2 ]
ret %struct.extmod* %27
}