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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDOUT_FILENO;
int dup(int /*<<< orphan*/);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  struct stat st;
  int fd;
  fd = dup(STDOUT_FILENO);
  if (fd < 0) {
    perror("dup(STDOUT_FILENO)");
    return (EXIT_FAILURE);
  }
  if (fstat(fd, &st) < 0) {
    perror("fstat(fd,&st)");
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
call   1030 <dup@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117e <main+0x4e>
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <main+0x8d>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <fstat@plt>
cmp    $0x0,%rax
jge    11b1 <main+0x81>
lea    0xe78(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <main+0x8d>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
call   1030 <dup@plt>
test   %eax,%eax
js     115d <main+0x2d>
mov    %rsp,%rsi
mov    %eax,%edi
call   1050 <fstat@plt>
test   %rax,%rax
js     1166 <main+0x36>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe9c(%rip),%rdi
jmp    116d <main+0x3d>
lea    0xea6(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e5f(%rip),%rax
jmp    1159 <main+0x29>

LLVM IR (-O0):
%struct.stat = type { i32 }
@STDOUT_FILENO = global i32 0
@.str = [19 x i8] c"dup(STDOUT_FILENO)\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"fstat(fd,&st)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @dup(i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %24
15: ; preds = %2
%16 = load i32, i32* %7
%17 = call i64 @fstat(i32 %16, %struct.stat* %6)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %24
22: ; preds = %15
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %19, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@STDOUT_FILENO = global i32 0
@.str = [19 x i8] c"dup(STDOUT_FILENO)\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"fstat(fd,&st)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @STDOUT_FILENO
%6 = tail call i32 @dup(i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i64 @fstat(i32 %6, %struct.stat* %3)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8, %2
%12 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %8 ]
%13 = tail call i32 @perror(i8* %12)
br label %14
14: ; preds = %11, %8
%15 = phi i32* [ @EXIT_SUCCESS, %8 ], [ @EXIT_FAILURE, %11 ]
%16 = load i32, i32* %15
ret i32 %16
}