#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 */
char *lookup(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
char tolower(char);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Usage: extension [path]\n");
    return 1;
  }
  char *url = argv[1];
  for (int i = 0, n = strlen(url); i < n; i++) {
    url[i] = tolower(url[i]);
  }
  const char *type = lookup(url);
  if (type == NULL) {
    return 1;
  } else {
    printf("%s\n", type);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1207 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11d1 <main+0x91>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <tolower@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <main+0x59>
mov    -0x18(%rbp),%rdi
call   1050 <lookup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f5 <main+0xb5>
movl   $0x1,-0x4(%rbp)
jmp    1207 <main+0xc7>
mov    -0x28(%rbp),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1190 <main+0x50>
mov    0x8(%rsi),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1177 <main+0x37>
mov    %eax,%r14d
xor    %ebx,%ebx
nop
movsbl (%r15,%rbx,1),%edi
call   1060 <tolower@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <main+0x20>
mov    %r15,%rdi
call   1050 <lookup@plt>
test   %rax,%rax
je     119c <main+0x5c>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    11a1 <main+0x61>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Usage: extension [path]\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
store i32 0, i32* %7
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %8
br label %20
20: ; preds = %35, %14
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call signext i8 @tolower(i8 signext %29)
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 %30, i8* %34
br label %35
35: ; preds = %24
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %20
38: ; preds = %20
%39 = load i8*, i8** %6
%40 = call i8* @lookup(i8* %39)
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 1, i32* %3
br label %47
44: ; preds = %38
%45 = load i8*, i8** %9
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %12, %43, %44
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@str = [24 x i8] c"Usage: extension [path]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %25
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = zext i32 %9 to i64
br label %16
13: ; preds = %16, %6
%14 = tail call i8* @lookup(i8* %8)
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %23
16: ; preds = %11, %16
%17 = phi i64 [ 0, %11 ], [ %21, %16 ]
%18 = getelementptr inbounds i8, i8* %8, i64 %17
%19 = load i8, i8* %18
%20 = tail call signext i8 @tolower(i8 signext %19)
store i8 %20, i8* %18
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %12
br i1 %22, label %13, label %16
23: ; preds = %13
%24 = tail call i32 @puts(i8* %14)
br label %25
25: ; preds = %23, %13, %4
%26 = phi i32 [ 1, %4 ], [ 0, %23 ], [ 1, %13 ]
ret i32 %26
}