#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int stegmp(char const *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
int stegmp_write(const char *bmp_file, const char *in_file) {
  if (strcmp(in_file, "-") == 0) {
    return stegmp(bmp_file, stdin);
  } else {
    int ret;
    FILE *fh = fopen(in_file, "r");
    if (fh == NULL) {
      fprintf(stderr, "%s: %m\n", in_file);
      return -1;
    }
    ret = stegmp(bmp_file, fh);
    fclose(fh);
    return ret;
  }
}


x86 assembly (clang, -O0):
<stegmp_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1195 <stegmp_write+0x45>
mov    -0x10(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%rsi
call   1070 <stegmp@plt>
mov    %eax,-0x4(%rbp)
jmp    11f8 <stegmp_write+0xa8>
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d9 <stegmp_write+0x89>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <stegmp_write+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <stegmp@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stegmp_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe9c(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11a1 <stegmp_write+0x51>
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bd <stegmp_write+0x6d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <stegmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    11da <stegmp_write+0x8a>
mov    0x2e40(%rip),%rax
mov    (%rax),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <stegmp@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [8 x i8] c"%s: %m\0A\00"
define i32 @stegmp_write(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i32*, i32** @stdin
%14 = call i32 @stegmp(i8* %12, i32* %13)
store i32 %14, i32* %3
br label %31
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %7
%18 = load i32*, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %31
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i32*, i32** %7
%27 = call i32 @stegmp(i8* %25, i32* %26)
store i32 %27, i32* %6
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %6
store i32 %30, i32* %3
br label %31
31: ; preds = %24, %20, %11
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [8 x i8] c"%s: %m\0A\00"
define i32 @stegmp_write(i8* %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32*, i32** @stdin
%7 = tail call i32 @stegmp(i8* %0, i32* %6)
br label %17
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %17
14: ; preds = %8
%15 = tail call i32 @stegmp(i8* %0, i32* %9)
%16 = tail call i32 @fclose(i32* %9)
br label %17
17: ; preds = %11, %14, %5
%18 = phi i32 [ %7, %5 ], [ -1, %11 ], [ %15, %14 ]
ret i32 %18
}