#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 *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int getformat(void) {
  int point;
  char fts[10];
  char *formats[] = {"",         "sgi8",  "sgi16", "sunras",
                     "farbfeld", "targa", "winbmp"};
  printf("format: ");
  scanf("%s", fts);
  for (point = 6; point; point--)
    if ((strcmp(fts, formats[point])) == 0)
      return point;
  printf("format not found\n");
  return 0;
}


x86 assembly (clang, -O0):
<getformat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x50(%rbp),%rdi
lea    0x2c8d(%rip),%rsi
mov    $0x38,%edx
call   1050 <memcpy@plt>
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
lea    -0x12(%rbp),%rsi
lea    0xebd(%rip),%rdi
call   1060 <scanf@plt>
movl   $0x6,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11c4 <getformat+0x84>
lea    -0x12(%rbp),%rdi
movslq -0x8(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11b1 <getformat+0x71>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <getformat+0x97>
jmp    11b6 <getformat+0x76>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1180 <getformat+0x40>
lea    0xe69(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getformat>:
push   %rbx
sub    $0x10,%rsp
lea    0xedc(%rip),%rdi
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0x6(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f7 <getformat+0xb7>
lea    0xe9b(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fe <getformat+0xbe>
lea    0xe7c(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1205 <getformat+0xc5>
lea    0xe5f(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120c <getformat+0xcc>
lea    0xe43(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1213 <getformat+0xd3>
lea    0xe28(%rip),%rsi
lea    0x6(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     121a <getformat+0xda>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    121f <getformat+0xdf>
mov    $0x6,%eax
jmp    121f <getformat+0xdf>
mov    $0x5,%eax
jmp    121f <getformat+0xdf>
mov    $0x4,%eax
jmp    121f <getformat+0xdf>
mov    $0x3,%eax
jmp    121f <getformat+0xdf>
mov    $0x2,%eax
jmp    121f <getformat+0xdf>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"sgi8\00"
@.str.2 = [6 x i8] c"sgi16\00"
@.str.3 = [7 x i8] c"sunras\00"
@.str.4 = [9 x i8] c"farbfeld\00"
@.str.5 = [6 x i8] c"targa\00"
@.str.6 = [7 x i8] c"winbmp\00"
@__const.getformat.formats = [7 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0)]
@.str.7 = [9 x i8] c"format: \00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [18 x i8] c"format not found\0A\00"
define i32 @getformat() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca [7 x i8*]
%5 = bitcast [7 x i8*]* %4 to i8*
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %7)
store i32 6, i32* %2
br label %9
9: ; preds = %23, %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [7 x i8*], [7 x i8*]* %4, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %13, i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = load i32, i32* %2
store i32 %21, i32* %1
br label %28
22: ; preds = %12
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = add nsw i32 %24, -1
store i32 %25, i32* %2
br label %9
26: ; preds = %9
%27 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %28
28: ; preds = %26, %20
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"sgi8\00"
@.str.2 = [6 x i8] c"sgi16\00"
@.str.3 = [7 x i8] c"sunras\00"
@.str.4 = [9 x i8] c"farbfeld\00"
@.str.5 = [6 x i8] c"targa\00"
@.str.6 = [7 x i8] c"winbmp\00"
@.str.7 = [9 x i8] c"format: \00"
@.str.8 = [3 x i8] c"%s\00"
@str = [17 x i8] c"format not found\00"
define i32 @getformat() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %2)
%5 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %0
%8 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %7
%11 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %10
%14 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %0, %7, %10, %13, %16, %19, %22
%25 = phi i32 [ 0, %22 ], [ 6, %0 ], [ 5, %7 ], [ 4, %10 ], [ 3, %13 ], [ 2, %16 ], [ 1, %19 ]
ret i32 %25
}