#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*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int parse_typearg(char *arg) {
  if (!arg)
    return -1;
  if (strlen(arg) != 3) {
    printf("Invalid file format: %s\n", arg);
    return -1;
  }
  if (!strcmp(arg, "bmp"))
    return 0;
  else if (!strcmp(arg, "png"))
    return 1;
  else {
    printf("Invalid file format: %s\n", arg);
    return -1;
  }
}


x86 assembly (clang, -O0):
<parse_typearg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <parse_typearg+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <parse_typearg+0xb2>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
je     1181 <parse_typearg+0x51>
mov    -0x10(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <parse_typearg+0xb2>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11a6 <parse_typearg+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <parse_typearg+0xb2>
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <parse_typearg+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <parse_typearg+0xb2>
mov    -0x10(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_typearg>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     118a <parse_typearg+0x5a>
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x3,%eax
jne    1170 <parse_typearg+0x40>
lea    0xec8(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1181 <parse_typearg+0x51>
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1185 <parse_typearg+0x55>
lea    0xe89(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    118a <parse_typearg+0x5a>
xor    %ebp,%ebp
jmp    118a <parse_typearg+0x5a>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Invalid file format: %s\0A\00"
@.str.1 = [4 x i8] c"bmp\00"
@.str.2 = [4 x i8] c"png\00"
define i32 @parse_typearg(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i32 -1, i32* %2
br label %27
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 -1, i32* %2
br label %27
14: ; preds = %7
%15 = load i8*, i8** %3
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14
store i32 0, i32* %2
br label %27
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %19
store i32 1, i32* %2
br label %27
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 -1, i32* %2
br label %27
27: ; preds = %24, %23, %18, %11, %6
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [25 x i8] c"Invalid file format: %s\0A\00"
@.str.1 = [4 x i8] c"bmp\00"
@.str.2 = [4 x i8] c"png\00"
define i32 @parse_typearg(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 3
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9, %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %9, %6, %1
%15 = phi i32 [ -1, %1 ], [ 0, %6 ], [ 1, %9 ], [ -1, %12 ]
ret i32 %15
}