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

/* Variables and functions */
scalar_t__ fputc(int, int /*<<< orphan*/ *);
int mywav_fwi32(FILE *fd, int num) {
  if (fputc((num)&0xff, fd) < 0)
    return (-1);
  if (fputc((num >> 8) & 0xff, fd) < 0)
    return (-1);
  if (fputc((num >> 16) & 0xff, fd) < 0)
    return (-1);
  if (fputc((num >> 24) & 0xff, fd) < 0)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<mywav_fwi32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
call   1030 <fputc@plt>
cmp    $0x0,%rax
jge    1147 <mywav_fwi32+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mywav_fwi32+0xbf>
mov    -0x14(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
call   1030 <fputc@plt>
cmp    $0x0,%rax
jge    1172 <mywav_fwi32+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mywav_fwi32+0xbf>
mov    -0x14(%rbp),%edi
sar    $0x10,%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
call   1030 <fputc@plt>
cmp    $0x0,%rax
jge    119d <mywav_fwi32+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mywav_fwi32+0xbf>
mov    -0x14(%rbp),%edi
sar    $0x18,%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rsi
call   1030 <fputc@plt>
cmp    $0x0,%rax
jge    11c8 <mywav_fwi32+0xb8>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <mywav_fwi32+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mywav_fwi32>:
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r15
movzbl %bl,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     1169 <mywav_fwi32+0x59>
movzbl %bh,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
test   %rax,%rax
js     1169 <mywav_fwi32+0x59>
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
test   %rax,%rax
js     1169 <mywav_fwi32+0x59>
shr    $0x18,%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
mov    %rax,%r14
sar    $0x3f,%r14
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @mywav_fwi32(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = and i32 %6, 255
%8 = load i32*, i32** %4
%9 = call i64 @fputc(i32 %7, i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %37
12: ; preds = %2
%13 = load i32, i32* %5
%14 = ashr i32 %13, 8
%15 = and i32 %14, 255
%16 = load i32*, i32** %4
%17 = call i64 @fputc(i32 %15, i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %3
br label %37
20: ; preds = %12
%21 = load i32, i32* %5
%22 = ashr i32 %21, 16
%23 = and i32 %22, 255
%24 = load i32*, i32** %4
%25 = call i64 @fputc(i32 %23, i32* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %20
store i32 -1, i32* %3
br label %37
28: ; preds = %20
%29 = load i32, i32* %5
%30 = ashr i32 %29, 24
%31 = and i32 %30, 255
%32 = load i32*, i32** %4
%33 = call i64 @fputc(i32 %31, i32* %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 -1, i32* %3
br label %37
36: ; preds = %28
store i32 0, i32* %3
br label %37
37: ; preds = %36, %35, %27, %19, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @mywav_fwi32(i32* nocapture %0, i32 %1) {
%3 = and i32 %1, 255
%4 = tail call i64 @fputc(i32 %3, i32* %0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = lshr i32 %1, 8
%8 = and i32 %7, 255
%9 = tail call i64 @fputc(i32 %8, i32* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = lshr i32 %1, 16
%13 = and i32 %12, 255
%14 = tail call i64 @fputc(i32 %13, i32* %0)
%15 = icmp slt i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = lshr i32 %1, 24
%18 = tail call i64 @fputc(i32 %17, i32* %0)
%19 = ashr i64 %18, 63
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %16, %11, %6, %2
%22 = phi i32 [ -1, %2 ], [ -1, %6 ], [ -1, %11 ], [ %20, %16 ]
ret i32 %22
}