#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*/ SIGTERM;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int kill_pppd_by_pid(int unit) {
  FILE *fp;
  int pid;
  char *pid_file[2] = {"/var/run/ppp0.pid", "/var/run/ppp1.pid"};
  if ((fp = fopen(pid_file[unit], "r")) == NULL)
    return 0;
  fscanf(fp, "%d", &pid);
  fclose(fp);
  kill(pid, SIGTERM);
  return 1;
}


x86 assembly (clang, -O0):
<kill_pppd_by_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2cae(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cab(%rip),%rax
mov    %rax,-0x28(%rbp)
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
lea    0xeb3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1190 <kill_pppd_by_pid+0x50>
movl   $0x0,-0x4(%rbp)
jmp    11c5 <kill_pppd_by_pid+0x85>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kill_pppd_by_pid>:
push   %rbx
sub    $0x10,%rsp
movslq %edi,%rax
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
lea    0xec7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119f <kill_pppd_by_pid+0x5f>
mov    %rax,%rbx
lea    0xeb5(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    $0x1,%eax
jmp    11a1 <kill_pppd_by_pid+0x61>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/var/run/ppp0.pid\00"
@.str.1 = [18 x i8] c"/var/run/ppp1.pid\00"
@__const.kill_pppd_by_pid.pid_file = [2 x i8*] [i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@SIGTERM = global i32 0
define i32 @kill_pppd_by_pid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [2 x i8*]
store i32 %0, i32* %3
%7 = bitcast [2 x i8*]* %6 to i8*
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 %9
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 0, i32* %2
br label %23
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %5
%21 = load i32, i32* @SIGTERM
%22 = call i32 @kill(i32 %20, i32 %21)
store i32 1, i32* %2
br label %23
23: ; preds = %15, %14
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [18 x i8] c"/var/run/ppp0.pid\00"
@.str.1 = [18 x i8] c"/var/run/ppp1.pid\00"
@reltable.kill_pppd_by_pid = [2 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str to i64), i64 ptrtoint ([2 x i32]* @reltable.kill_pppd_by_pid to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.1 to i64), i64 ptrtoint ([2 x i32]* @reltable.kill_pppd_by_pid to i64)) to i32)]
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@SIGTERM = global i32 0
define i32 @kill_pppd_by_pid(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = sext i32 %0 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([2 x i32]* @reltable.kill_pppd_by_pid to i8*), i64 %5)
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = call i32 @fclose(i32* %7)
%12 = load i32, i32* %2
%13 = load i32, i32* @SIGTERM
%14 = call i32 @kill(i32 %12, i32 %13)
br label %15
15: ; preds = %1, %9
%16 = phi i32 [ 1, %9 ], [ 0, %1 ]
ret i32 %16
}