#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 SymTab {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ symtab_lookup(struct SymTab **, char *, char *,
                         int /*<<< orphan*/ *);
int guess_output(struct SymTab **prgSyms, char *out) {
  int x, pIdx = -1;
  char fmtname[64];
  if (symtab_lookup(prgSyms, "$outfmt", fmtname, NULL) != 0) {
    printf("INFO: Unknown output format, defaulting to hex\n");
    sprintf(fmtname, "hex");
  }
  for (x = 0; out[x] != '\0'; x++) {
    if (out[x] == '.') {
      pIdx = x;
    }
  }
  if (pIdx == -1) {
    return -1;
  }
  sprintf(&out[pIdx + 1], "%s", fmtname);
  return 0;
}


x86 assembly (clang, -O0):
<guess_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xeaa(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <symtab_lookup@plt>
cmp    $0x0,%rax
je     1187 <guess_output+0x57>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11d1 <guess_output+0xa1>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11be <guess_output+0x8e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11c3 <guess_output+0x93>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <guess_output+0x5e>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11e7 <guess_output+0xb7>
movl   $0xffffffff,-0x4(%rbp)
jmp    120f <guess_output+0xdf>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rdi
lea    -0x60(%rbp),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_output>:
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
lea    0xec1(%rip),%rsi
mov    %rsp,%rdx
xor    %ecx,%ecx
call   1050 <symtab_lookup@plt>
test   %rax,%rax
je     1161 <guess_output+0x31>
lea    0xeb3(%rip),%rdi
call   1040 <puts@plt>
movl   $0x786568,(%rsp)
mov    $0xffffffff,%eax
xor    %ecx,%ecx
jmp    1176 <guess_output+0x46>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
add    $0x1,%rcx
movzbl (%rbx,%rcx,1),%edx
cmp    $0x2e,%dl
je     1170 <guess_output+0x40>
test   %dl,%dl
jne    1172 <guess_output+0x42>
cmp    $0xffffffff,%eax
je     119e <guess_output+0x6e>
cltq
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
mov    %rsp,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    11a3 <guess_output+0x73>
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.SymTab = type { i32 }
@.str = [8 x i8] c"$outfmt\00"
@.str.1 = [48 x i8] c"INFO: Unknown output format, defaulting to hex\0A\00"
@.str.2 = [4 x i8] c"hex\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @guess_output(%struct.SymTab** %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.SymTab**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i8]
store %struct.SymTab** %0, %struct.SymTab*** %4
store i8* %1, i8** %5
store i32 -1, i32* %7
%9 = load %struct.SymTab**, %struct.SymTab*** %4
%10 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%11 = call i64 @symtab_lookup(%struct.SymTab** %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %10, i32* null)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %13, %2
store i32 0, i32* %6
br label %18
18: ; preds = %37, %17
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %40
26: ; preds = %18
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %34, label %36
34: ; preds = %26
%35 = load i32, i32* %6
store i32 %35, i32* %7
br label %36
36: ; preds = %34, %26
br label %37
37: ; preds = %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %18
40: ; preds = %18
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 -1, i32* %3
br label %52
44: ; preds = %40
%45 = load i8*, i8** %5
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %8, i64 0, i64 0
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %50)
store i32 0, i32* %3
br label %52
52: ; preds = %44, %43
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.SymTab = type { i32 }
@.str = [8 x i8] c"$outfmt\00"
@str = [47 x i8] c"INFO: Unknown output format, defaulting to hex\00"
define i32 @guess_output(%struct.SymTab** %0, i8* %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i64 @symtab_lookup(%struct.SymTab** %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %4, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%9 = bitcast [64 x i8]* %3 to i32*
store i32 7890280, i32* %9
br label %10
10: ; preds = %7, %2
br label %11
11: ; preds = %10, %18
%12 = phi i64 [ %20, %18 ], [ 0, %10 ]
%13 = phi i32 [ %19, %18 ], [ -1, %10 ]
%14 = getelementptr inbounds i8, i8* %1, i64 %12
%15 = load i8, i8* %14
switch i8 %15, label %18 [
i8 0, label %21
i8 46, label %16
]
16: ; preds = %11
%17 = trunc i64 %12 to i32
br label %18
18: ; preds = %11, %16
%19 = phi i32 [ %17, %16 ], [ %13, %11 ]
%20 = add nuw i64 %12, 1
br label %11
21: ; preds = %11
%22 = icmp eq i32 %13, -1
br i1 %22, label %28, label %23
23: ; preds = %21
%24 = add nuw nsw i32 %13, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = call i8* @strcpy(i8* dereferenceable(1) %26, i8* %4)
br label %28
28: ; preds = %21, %23
%29 = phi i32 [ 0, %23 ], [ -1, %21 ]
ret i32 %29
}