#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct stat *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
void check_arg(int argc, char **argv) {
  struct stat buf1, buf2;
  bzero(&buf1, sizeof(struct stat));
  bzero(&buf2, sizeof(struct stat));
  stat(argv[1], &buf1);
  stat(argv[2], &buf2);
  if (!S_ISREG(buf1.st_mode) || !S_ISDIR(buf2.st_mode)) {
    fprintf(stderr, "invalid arguments\n");
    exit(2);
  }
}


x86 assembly (clang, -O0):
<check_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
lea    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x18(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%eax
je     11cf <check_arg+0x6f>
mov    -0x20(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11ee <check_arg+0x8e>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_arg>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x4,%esi
call   1070 <bzero@plt>
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1050 <stat@plt>
mov    0x10(%rbx),%rdi
mov    %r15,%rsi
call   1050 <stat@plt>
mov    0x8(%rsp),%edi
call   1060 <S_ISREG@plt>
test   %eax,%eax
je     11c9 <check_arg+0x69>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %eax,%eax
je     11c9 <check_arg+0x69>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"invalid arguments\0A\00"
define void @check_arg(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.stat
%6 = alloca %struct.stat
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i32 @bzero(%struct.stat* %5, i32 4)
%8 = call i32 @bzero(%struct.stat* %6, i32 4)
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @stat(i8* %11, %struct.stat* %5)
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @stat(i8* %15, %struct.stat* %6)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @S_ISREG(i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @S_ISDIR(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %21, %2
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 2)
unreachable
30: ; preds = %21
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [19 x i8] c"invalid arguments\0A\00"
define void @check_arg(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @bzero(%struct.stat* %3, i32 4)
%8 = call i32 @bzero(%struct.stat* %4, i32 4)
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @stat(i8* %10, %struct.stat* %3)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @stat(i8* %13, %struct.stat* %4)
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = tail call i32 @S_ISREG(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %2
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i32 @S_ISDIR(i32 %21)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19, %2
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 2)
unreachable
28: ; preds = %19
ret void
}