#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 */

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int chmod(char *, int);
int close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ warn(char *, char *);
void pcap_touch(char *pcap_path) {
  int fd = open(pcap_path, O_WRONLY | O_CREAT, 0644);
  if (fd < 0) {
    warn("could not touch %s", pcap_path);
  } else {
    int rv = close(fd);
    if (rv) {
      warn("could not close %s after touch", pcap_path);
    }
    rv = chmod(pcap_path, 0644);
    if (rv) {
      warn("could not chmod %s", pcap_path);
    }
    fprintf(stderr, "touched %s\n", pcap_path);
  }
}


x86 assembly (clang, -O0):
<pcap_touch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119e <pcap_touch+0x4e>
mov    -0x8(%rbp),%rsi
lea    0xe6c(%rip),%rdi
call   1030 <warn@plt>
jmp    1207 <pcap_touch+0xb7>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11c3 <pcap_touch+0x73>
mov    -0x8(%rbp),%rsi
lea    0xe55(%rip),%rdi
call   1030 <warn@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1a4,%esi
call   1060 <chmod@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ee <pcap_touch+0x9e>
mov    -0x8(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1030 <warn@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcap_touch>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e6d(%rip),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     11c7 <pcap_touch+0x77>
mov    %eax,%edi
call   1040 <close@plt>
test   %eax,%eax
je     118e <pcap_touch+0x3e>
lea    0xe8d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <warn@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1060 <chmod@plt>
test   %eax,%eax
je     11ae <pcap_touch+0x5e>
lea    0xe8c(%rip),%rdi
mov    %rbx,%rsi
call   1030 <warn@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    %rbx,%rdx
pop    %rbx
jmp    1050 <fprintf@plt>
lea    0xe32(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <warn@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [19 x i8] c"could not touch %s\00"
@.str.1 = [31 x i8] c"could not close %s after touch\00"
@.str.2 = [19 x i8] c"could not chmod %s\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"touched %s\0A\00"
define void @pcap_touch(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8, i32 420)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %35
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 @close(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = call i32 @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %15
%24 = load i8*, i8** %2
%25 = call i32 @chmod(i8* %24, i32 420)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i8*, i8** %2
%30 = call i32 @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %23
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %2
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %31, %12
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [19 x i8] c"could not touch %s\00"
@.str.1 = [31 x i8] c"could not close %s after touch\00"
@.str.2 = [19 x i8] c"could not chmod %s\00"
@stderr = global i32 0
@.str.3 = [12 x i8] c"touched %s\0A\00"
define void @pcap_touch(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4, i32 420)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %22
9: ; preds = %1
%10 = tail call i32 @close(i32 %5)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %12, %9
%15 = tail call i32 @chmod(i8* %0, i32 420)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @warn(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %19, %7
ret void
}