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

/* Variables and functions */
int /*<<< orphan*/ magic_close(struct magic_set *);
char *magic_error(struct magic_set *);
char *magic_file(struct magic_set *, char *);
int magic_load(struct magic_set *, int /*<<< orphan*/ *);
struct magic_set *magic_open(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  struct magic_set *ms;
  const char *m;
  int i;
  if (argc < 2)
    return 1;
  ms = magic_open(0x000);
  if (ms == NULL) {
    printf("ERROR: out of memory\n");
    return 1;
  }
  if (magic_load(ms, NULL) == -1) {
    printf("ERROR: %s\n", magic_error(ms));
    return 1;
  }
  for (i = 1; i < argc; i++) {
    if ((m = magic_file(ms, argv[i])) == NULL)
      printf("ERROR: %s\n", magic_error(ms));
    else
      printf("%s: %s\n", argv[i], m);
  }
  magic_close(ms);
  return 0;
}


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)
jge    118c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    128e <main+0x12e>
xor    %edi,%edi
call   1080 <magic_open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <main+0x5c>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128e <main+0x12e>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <magic_load@plt>
cmp    $0xffffffff,%eax
jne    11f8 <main+0x98>
mov    -0x18(%rbp),%rdi
call   1060 <magic_error@plt>
mov    %rax,%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128e <main+0x12e>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127e <main+0x11e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <magic_file@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124d <main+0xed>
mov    -0x18(%rbp),%rdi
call   1060 <magic_error@plt>
mov    %rax,%rsi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126b <main+0x10b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1270 <main+0x110>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ff <main+0x9f>
mov    -0x18(%rbp),%rdi
call   1070 <magic_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r15d
cmp    $0x2,%edi
jl     1246 <main+0xd6>
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
call   1090 <magic_open@plt>
test   %rax,%rax
je     121f <main+0xaf>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
call   1030 <magic_load@plt>
cmp    $0xffffffff,%eax
je     122d <main+0xbd>
mov    %ebp,%r13d
mov    $0x1,%ebp
lea    0xe3c(%rip),%r15
lea    0xe40(%rip),%r12
jmp    11ea <main+0x7a>
nopl   (%rax)
mov    (%rbx,%rbp,8),%rsi
mov    %r12,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     1212 <main+0xa2>
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
call   1050 <magic_file@plt>
test   %rax,%rax
jne    11d0 <main+0x60>
mov    %r14,%rdi
call   1070 <magic_error@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11e1 <main+0x71>
mov    %r14,%rdi
call   1080 <magic_close@plt>
xor    %r15d,%r15d
jmp    1246 <main+0xd6>
lea    0xded(%rip),%rdi
call   1040 <puts@plt>
jmp    1246 <main+0xd6>
mov    %r14,%rdi
call   1070 <magic_error@plt>
lea    0xdc4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.magic_set = type { i32 }
@.str = [22 x i8] c"ERROR: out of memory\0A\00"
@.str.1 = [11 x i8] c"ERROR: %s\0A\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.magic_set*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %59
12: ; preds = %2
%13 = call %struct.magic_set* @magic_open(i32 0)
store %struct.magic_set* %13, %struct.magic_set** %6
%14 = load %struct.magic_set*, %struct.magic_set** %6
%15 = icmp eq %struct.magic_set* %14, null
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %59
18: ; preds = %12
%19 = load %struct.magic_set*, %struct.magic_set** %6
%20 = call i32 @magic_load(%struct.magic_set* %19, i32* null)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load %struct.magic_set*, %struct.magic_set** %6
%24 = call i8* @magic_error(%struct.magic_set* %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %59
26: ; preds = %18
store i32 1, i32* %8
br label %27
27: ; preds = %53, %26
%28 = load i32, i32* %8
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %56
31: ; preds = %27
%32 = load %struct.magic_set*, %struct.magic_set** %6
%33 = load i8**, i8*** %5
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i8* @magic_file(%struct.magic_set* %32, i8* %37)
store i8* %38, i8** %7
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %44
40: ; preds = %31
%41 = load %struct.magic_set*, %struct.magic_set** %6
%42 = call i8* @magic_error(%struct.magic_set* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %52
44: ; preds = %31
%45 = load i8**, i8*** %5
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = load i8*, i8** %7
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %49, i8* %50)
br label %52
52: ; preds = %44, %40
br label %53
53: ; preds = %52
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
br label %27
56: ; preds = %27
%57 = load %struct.magic_set*, %struct.magic_set** %6
%58 = call i32 @magic_close(%struct.magic_set* %57)
store i32 0, i32* %3
br label %59
59: ; preds = %56, %22, %16, %11
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
%struct.magic_set = type { i32 }
@.str.1 = [11 x i8] c"ERROR: %s\0A\00"
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@str = [21 x i8] c"ERROR: out of memory\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %34, label %4
4: ; preds = %2
%5 = tail call %struct.magic_set* @magic_open(i32 0)
%6 = icmp eq %struct.magic_set* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %34
9: ; preds = %4
%10 = tail call i32 @magic_load(%struct.magic_set* %5, i32* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = zext i32 %0 to i64
br label %17
14: ; preds = %9
%15 = tail call i8* @magic_error(%struct.magic_set* %5)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %34
17: ; preds = %12, %29
%18 = phi i64 [ 1, %12 ], [ %30, %29 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i8* @magic_file(%struct.magic_set* %5, i8* %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = tail call i8* @magic_error(%struct.magic_set* %5)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %29
26: ; preds = %17
%27 = load i8*, i8** %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %21)
br label %29
29: ; preds = %23, %26
%30 = add nuw nsw i64 %18, 1
%31 = icmp eq i64 %30, %13
br i1 %31, label %32, label %17
32: ; preds = %29
%33 = tail call i32 @magic_close(%struct.magic_set* %5)
br label %34
34: ; preds = %2, %32, %14, %7
%35 = phi i32 [ 1, %7 ], [ 1, %14 ], [ 0, %32 ], [ 1, %2 ]
ret i32 %35
}